Please enable JavaScript to view this site.

A-Shell Reference

Added October 2016

IFELSE(cond, expr1, expr2)

IFELSE$(cond, expr1, expr2)

These functions are conveniences which can often eliminate the need for a temporary variable or duplication of statements that differ only by a single either/or choice.

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.

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$, ..History

See Also

IFE and IFE$

History

2016 September, A-Shell 6.3.1526 and compiler edit 773:  Function added to A-Shell.