lang • iif

IIf

Value = IIf ( Test AS Boolean , TrueExpression , FalseExpression ) Value = If ( Test AS Boolean , TrueExpression , FalseExpression )

Evaluate the Test expression, and return TrueExpression if this expression is TRUE, or FalseExpression if this expression is FALSE.

BE CAREFUL!

Contrary to IF, or the C/Perl ? operator, both TrueExpression and FalseExpression are evaluated, whatever the value of Test is.

Examples

X = 7
Print If((X Mod 2) = 0, "even", "odd")
odd
' Never do the following in real code, because it is not translatable!
X = 7
Print "You have " & X & " message" & If(X <> 1, "s", "") & " waiting."
You have 7 messages waiting.
Print If((X Mod 2) = 1, "odd", 1 / 0)
Division by zero

See also