Aconditional expressionhas the formif c then t else f
,where `c'' is an expression of typeBoolean
,andt
andf
are expressions of any type, butt
andf
must have the same type.
Evaluation of conditional expressions is non-strict. The evaluation semantics ofif c then t else f
are:
- The condition
c
is always evaluated. - If
c
evaluates totrue
,the expressiont
is evaluated andf
remains unevaluated. The whole expression reduces to the value oft
. - If
c
evaluates tofalse
,the expressionf
is evaluated andt
remains unevaluated. The whole expression reduces to the value off
.
The keywordsif
,then
,andelse
each introduce aBlockas follows:
if
<block>
then
<block>
else
<block>