HP Pascal/iX Reference Manual (31502-90022)

6-: 8
NOTE ELSE parts are always associated with the nearest preceding
unmatched IF statement.
A common use of the IF statement is to select an action from several
choices. This often appears in the following form:
IF e1 THEN
...
ELSE IF e2 THEN
...
ELSE IF e3 THEN
...
ELSE
...
This form is particularly useful to test for conditions involving real
numbers or string literals of more than one character, since these types
are not legal in CASE labels.
Syntax
If_statement
Example
PROGRAM show_if (output);
VAR
i,j : integer;
s : PACKED ARRAY [1..5] OF char;
found: Boolean;
BEGIN
.
.
IF i = 0 THEN writeln ('i = 0'); { IF with no ELSE. }
IF found THEN { IF with an ELSE part. }
writeln ('Found it')
ELSE
writeln ('Still looking');
.
.
IF i = j THEN { Select among different }
writeln ('i = j') { Boolean expressions. }
ELSE IF i < j THEN
writeln ('i < j')
ELSE { i > j }
writeln ('i > j');
.