Choice

Choosing between two alternatives depending on a condition is written in Elan as:


\begin{elan}
IF condition
THEN
part for condition true
ELSE
part for condition false
FI
\end{elan}

If the condition evaluates to true, then the paragraph between THEN and ELSE (the ``then-part'') is executed, and the rest up to the FI skipped. In the contrary case, the then-part is skipped, and the paragraph between ELSE and FI is executed (the ``else-part''). The keyword FI may also be spelled as ENDIF.

This primary form of choice has two variations for common needs. If there is nothing to do in the else-part, then the choice can be simplified by leaving out the else-part:


\begin{elan}
IF it looks like rain
THEN
take the umbrella with you
FI
\end{elan}

In case the weather is fine you do nothing (ELSE do nothing was omitted). For decision cascades like


\begin{elan}
IF condition 1
THEN
action 1
ELSE
IF condition 2
THEN
action 2
ELSE
IF
...
FI
FI
FI
\end{elan}

Elan offers another variant of the choice construction:


\begin{elan}
IF condition 1
THEN
action 1
ELIF condition 2
THEN
action 2
ELIF
...
ELSE
action for all conditions above failing
FI
\end{elan}

Also in this case, an empty else-part may be omitted.