# IFELSE() and IFELSE\$()
> [HTML Version](ifelseandifelse$().htm)
_Added October 2016_
**IFELSE(cond, expr1, expr2)**
**IFELSE\$(cond, expr1, expr2)**
These functions allow IF/THEN/ELSE logic to be embedded within a larger statement, eliminating the need for a temporary variable or additional/duplicated statements to deal with an either/or bifurcation.
Each takes a conditional expression (_cond_) and two value expressions (_expr1_ and _expr2_). If the conditional expression evaluates to true, then the function returns the value of _expr1_, else it returns the value of _expr2_. IFELSE() returns a numeric value and IFELSE\$() returns a string value.
Note that although _cond_ is normally provided in the form of a relational (boolean) expression evaluating to true (-1) or false (0), the compiler is more lenient, allowing a string expression, variable or literal value—even though ill-advised. See _History_ below and [Logical vs. Arithmetic Operators](logicalvsarithoperators.htm.md) for details.
**Examples**
Consider the case where you want to print a value with one of two masks depending on whether the value is less than 1. You might code it like this:
if VALUE >= 1 then
PRINT VALUE USING "#####"
else
PRINT VALUE USING "#.###"
endif
With the IFELSE\$() function, you can eliminate the IF statement and reduce the two PRINT statements to one:
PRINT VALUE USING IFELSE\$(VALUE>=1,"#####","#.###")
Or, in the case of larger statements where you are more likely to introduce temporary variables than to repeat variations of the statement, IFELSE() can eliminate the need for a temporary variable, e.g.
if flag'disable then
CSTATE = MBST\_DISABLE
else
CSTATE = MBST\_ENABLE
endif
xcall AUI, AUI\_CONTROL, CTLOP\_ADD, CTLID\$, CTEXT\$, CSTATE, CTYPE\$, CMD\$, FUNC\$, ...
The above can be reduced to a single statement using IFELSE:
xcall AUI, AUI\_CONTROL, CTLOP\_ADD, CTLID\$, CTEXT\$, ifelse(flag'disable,MBST\_DISABLE,MBST\_ENABLE), CTYPE\$, CMD\$, FUNC\$, ...
**See Also**
• [IFE()](ife()andife$().htm.md) and [IFE\$()](ife()andife$().htm.md)
**History**
2026 May, A-Shell 7.0.1786.2, compiler edit 1083: String _cond_ expressions are now explicitly converted to numeric values using the VAL() function. Previously, the interpretation of such a string expression as a boolean was ambiguous, depending on the prior state of the numeric expression stack.
2016 September, A-Shell 6.3.1526, compiler edit 773: Function added to A-Shell.