HP Pascal/iX Reference Manual (31502-90022)

6: 9
.
IF s = 'RED' THEN { This IF statement }
i := 1 { cannot be rewritten as }
ELSE IF s = 'GREEN' THEN { a CASE statement. }
i := 2
ELSE IF s = 'BLUE' THEN
i := 3;
END.
FOR .. DO
The FOR statement executes a statement a predetermined number of times.
The FOR statement consists of the reserved word FOR, a control variable
initialized by an ordinal expression known as the
initial value
, either
the reserved word TO indicating an increment or the reserved word DOWNTO
indicating a decrement, another ordinal expression known as the
final
value
, the reserved word DO, and a statement.
The control variable is assigned each value of the range during the
corresponding iteration of the statement. It must be an ordinal variable
and may not be a component of a structured variable or a locally declared
procedure or function parameter. The control variable may be a local or
global variable. Non-local variables are not allowed. The initial and
final values are ordinal expressions that must be assignment compatible
with the control variable. After completion of the FOR statement, the
control variable is undefined.
Syntax
For_statement:
When the system executes a FOR statement, the following occurs:
1. It evaluates the initial and final values and assigns the initial
value to the control variable.
2. It executes the statement after DO.
3. It repeatedly tests the current value of the control variable and
final value for inequality, increments or decrements the control
variable, and executes the statement after DO.
In a FOR..TO construction, the system never executes the statement after
DO if the initial value is greater than the final value. In a
FOR..DOWNTO construction, the statement is never executed if the initial
value is less than the final value.