if
condition then
true-expression else
false-expression
Condition yields a boolean
. True-expression and false-expression yield any variant
s.
The if
operator introduces a conditional expression. If the condition given in the if
clause is true
, the entire expression evaluates to the value given in the then
clause. If the condition is false
, the entire expression evaluates to the value given in the else
clause.
The if
operator is short-circuited. If the condition given in the if
clause is true
, only the expression given in the then
clause is evaluated. If the condition given in the if
clause is false
, only the expression given in the else
clause is evaluated. Never are both expressions evaluated. This has considerable implications if either expression calls a function that has side-effects.