Quick start manual
Syntactic elements
4-25
Declarations and statements
is equivalent to
if ... { expression1 } then
begin
if ... { expression2 } then
... { statement1 }
else
... { statement2 }
end;
The rule is that nested conditionals are parsed starting from the innermost
conditional, with each else bound to the nearest available if on its left. To force the
compiler to read our example in the second way, you would have to write it
explicitly as
if ... { expression1 } then
begin
if ... { expression2 } then
... { statement1 }
end
else
... { statement2 } ;
Case statements
The case statement may provide a readable alternative to deeply nested if
conditionals. A case statement has the form
case selectorExpression of
caseList
1
: statement
1
;
ƒ
caseList
n
: statement
n
;
end
where selectorExpression is any expression of an ordinal type (string types are invalid)
and each caseList is one of the following:
• A numeral, declared constant, or other expression that the compiler can evaluate
without executing your program. It must be of an ordinal type compatible with
selectorExpression. Thus 7, True, 4 + 5 * 3, 'A', and Integer('A') can all be used as
caseLists, but variables and most function calls cannot. (A few built-in functions
like Hi and Lo can occur in a caseList. See “Constant expressions” on page 5-44.)
• A subrange having the form First..Last, where First and Last both satisfy the
criterion above and First is less than or equal to Last.
• A list having the form item
1
, ..., item
n
, where each item satisfies one of the criteria
above.