A conditional expression has the form if c then t else f, where c is an expression of type Boolean, and t and f are expressions of any type, but t and f must have the same type.
Evaluation of conditional expressions is non-strict. The evaluation semantics of if c then t else f are:
- The condition
cis always evaluated. - If
cevaluates totrue, the expressiontis evaluated andfremains unevaluated. The whole expression reduces to the value oft. - If
cevaluates tofalse, the expressionfis evaluated andtremains unevaluated. The whole expression reduces to the value off.
The keywords if, then, and else each introduce a block as follows:
if
true
then
"codeblock here"
else
"another codeblock"