Purpose |
Return one of two values based upon a TRUE/FALSE evaluation. |
Syntax |
var = IIF(num_expression, truepart, falsepart) var& = IIF&(num_expression, truepart&, falsepart&) var$ = IIF$(num_expression, truepart$, falsepart$) |
Remarks |
IIF expects parts of any numeric type. IIF&
expects parts optimized for long integer
type. IIF$ expects parts of
If num_expression evaluates to TRUE (non-zero), the truepart is returned, else the falsepart is returned. num_expression is evaluated as a normal PowerBASIC Boolean expression, which offers short-circuit expression evaluation as needed. IIF(1 AND 2, 3, 4) would return the truepart (3) because both terms in num_expression are TRUE, and therefore evaluate to TRUE. To force a bitwise evaluation of num_expression, enclose it in parentheses. For example, IIF$( (1 AND 2), "True", "False") would return "False". IIF% is recognized as a valid synonym for IIF&. |
Restrictions |
Contrary to the implementation in some other languages, only the selected expression (truepart or falsepart) is evaluated at run-time, not both. This ensures optimum execution speed, as well as the elimination of unanticipated side effects. |
See also |
|
Example |
iLOGFONT.lfWeight = IIF&(Weight&, 700&, 400&) Score& = Score& + IIF&(Answer = %FALSE, 0, 10) |