Description
"If..Else" constructs are used to perform as exclusive alternatives
either one group of instructions or an alternate group of instructions.
The syntax of an "If..Else" construct is:
If <conditional expression> then
<statement>
else
<statement>;
If the condition is true the statement following the "then" is performed. If the condition is not true the statement following the "else"
is performed. For example:
If XAxis.ActualPosition > 2000 then
XAxisBeyondLimit:=true
else
XAxisBeyondLimit:=false;
A semicolon does not follow the statement preceding the "else". The
entire construct, from the compiler's point of view, is one single
statement. Semicolons do not come until the end of the statement. If
an unnecessary semicolon is found before the "else" the compiler
will indicate it should be removed.
If..Else statements can be nested to produce one-action-from-many
type selections. For example:
if Today=Monday then
Prompter.Writeln(‘What happened to the weekend?’)
else if Today=Tuesday then
Prompter.Writeln(‘Where is the coffee?’)
else if Today=Wednesday then
Prompter.Writeln(‘Half way there....’)
else if Today=Thursday then
Prompter.Writeln(‘We are almost there...’)
else if Today=Friday then
Prompter.Writeln(‘TGIF!’)
else
Prompter.Writeln(‘It s the weekend!’);
The Last else handles all the cases that did not qualify in the proceeding tests. Note again, that the semicolon does not occur until
after the last statement to conclude the entire group. The language does not have an explicit "Case" statement. This "If..Else"
structure can accomplish the behavior of a case statement.