HP Pascal/iX Reference Manual (31502-90022)

6-: 10
The FOR statement:
FOR control_var := initial TO final DO
statement
is equivalent to the statement:
BEGIN
temp1 := initial; {No evaluation order is required }
temp2 := final; {for temp1 and temp2. }
IF temp1 <= temp2 THEN
BEGIN
control_var := temp1;
WHILE control_var <= temp2 DO
BEGIN
statement;
control_var := succ(control_var); { increment }
END;
END
ELSE; { Don't execute the statement at all;}
END; { control_var is now undefined. }
The FOR statement:
FOR control_var := initial DOWNTO final DO
statement
is equivalent to the statement:
BEGIN
temp1 := initial; {No evaluation order is required }
temp2 := final; {for temp1 and temp2. }
IF temp1 >= temp2 THEN
BEGIN
control_var := temp1;
WHILE control_var >= temp2 DO
BEGIN
statement;
control_var := pred(control_var); { decrement }
END;
END
ELSE; { Don't execute the statement at all;}
END; { control_var is now undefined. }
In the statement after DO, it is an error if assignment is made to the
control variable. It cannot be used on the left-hand side of an
assignment statement, passed as a reference parameter or used as the
control variable of a second FOR statement nested within the first.
Furthermore, it may not appear as a parameter for the standard procedures
read
or
readln
.
The system determines the range of values for the control variable by
evaluating the two ordinal expressions once, and only once, before making
any assignment to the control variable. So the statement sequence:
i := 5;
FOR i := pred(i) TO succ(i) DO writeln('i=',i:1);
writes:
i=4
i=5
i=6
instead of:
i=4
i=5