FOR
operand1
|
[:]= | operand2 | |||||
EQ |
|||||||
FROM |
|||||||
TO
|
operand3
[[STEP ] operand4]
|
||||||
THRU |
|||||||
statement | |||||||
END-FOR
|
(structured mode only) | ||||||
[LOOP ]
|
(reporting mode only) |
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statements: REPEAT | ESCAPE
Belongs to Function Group: Loop Execution
The FOR
statement is used to initiate a processing loop and
to control the number of times the loop is processed.
Before the FOR
loop is entered, the values of the operands
are checked to ensure that they are consistent (that is, the value of
operand3 can be reached or exceeded by repeatedly
adding operand4 to
operand2). If the values are not consistent, the
FOR
loop is not entered (however, no error message is output,
except when the STEP
value is zero).
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1 | S | N | P | I | F | yes | yes | ||||||||||||
operand2 | C | S | N | N | P | I | F | yes | no | ||||||||||
operand3 | C | S | N | N | P | I | F | yes | no | ||||||||||
operand4 | C | S | N | N | P | I | F | yes | no |
Syntax Element Description:
** Example 'FOREX1S': FOR (structured mode) ************************************************************************ DEFINE DATA LOCAL 1 #INDEX (I1) 1 #ROOT (N2.7) END-DEFINE * FOR #INDEX 1 TO 5 COMPUTE #ROOT = SQRT (#INDEX) WRITE NOTITLE '=' #INDEX 3X '=' #ROOT END-FOR * SKIP 1 FOR #INDEX 1 TO 5 STEP 2 COMPUTE #ROOT = SQRT (#INDEX) WRITE '=' #INDEX 3X '=' #ROOT END-FOR * END
#INDEX: 1 #ROOT: 1.0000000 #INDEX: 2 #ROOT: 1.4142135 #INDEX: 3 #ROOT: 1.7320508 #INDEX: 4 #ROOT: 2.0000000 #INDEX: 5 #ROOT: 2.2360679 #INDEX: 1 #ROOT: 1.0000000 #INDEX: 3 #ROOT: 1.7320508 #INDEX: 5 #ROOT: 2.2360679
Equivalent reporting-mode example: FOREX1R.