A Boolean expression has typeBoolean
which has two values,true
andfalse
.
Conditional expressions
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>
Boolean conjunction and disjunction
ABoolean conjunction expressionis aBoolean
expression of the forma && b
wherea
andb
areBoolean
expressions. Note that {&&} is not a function, but built-in syntax.
The evaluation semantics ofa && b
are equivalent toif a then b else false
.
ABoolean disjunction expressionis aBoolean
expression of the forma || b
wherea
andb
areBoolean
expressions. Note that {||} is not a function, but built-in syntax.
The evaluation semantics ofa || b
are equivalent toif a then true else b
.