Language Reference/Terms/If-then-else

if-then-else can be used both as a statement and as an expression.

if-then-else (statement)
The if-then-eslse statement conditionally executes a group of statements.

: if  then  -list-opt -opt end if

: elseif  then 

: else 

The following two terms are equivalents.

if Cond1 then T1 elseif Cond2 then T2 else T3 end if

if Cond1 then T1 else if Cond2 then T2 else T3 end if end if

Consider the schematic if then else term:

if Cond then T1 else T2 end if

First Cond is evaluated, if it succeeds then T1 is evaluated otherwise T2</vp> is evaluated.

Cond</vp> is followed by an implicit cut, which turns:
 * a nondeterm</vp> condition into a determ</vp> condition and
 * a multi</vp> condition into a procedure</vp>.

Cond</vp> is a cut-scope (see ).

For readability sake, we always recommend using "or</vp>" instead of ";</vp>". Likewise we also recommend using "and</vp>" (instead of ",</vp>") when it (as in the condition above) represents a logical "condition" rather than a "sequentation".

Leaving out the else</vp>-part is just shorthand for writing that else</vp> succeed, i.e.

if <Cond> then <Term> end if

is short-hand for

if <Cond> then <Term> else succeed end if

if-then-else (expression)
The if-then-else expression conditionally evaluates expressions.

Syntactically it is same as the if-then-else statement, but and the terms in the branches must be expressions and the entire if-then-else expression will itself evaluate to a value.

The shorthand writings that leave out the else-part does not make sense for the expression.