FOR
operand1
|
[:]= |
|||||||||
|
||||||||||
STEP |
||||||||||
statement | ||||||||||
END-FOR
|
(structured mode only) | |||||||||
[LOOP ]
|
(reporting mode only) |
Note:
For compatibility reasons, the keywords :=
,
EQ
, FROM
, TO
, THRU
and
STEP
are optional if the corresponding subsequent operand
(operand2
,
operand3
or
operand4
) is used instead of an
arithmetic expression.
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 | E | N | P | I | F | yes | no | ||||||||||
operand3
|
C | S | N | E | N | P | I | F | yes | no | ||||||||||
operand4
|
C | S | N | E | N | P | I | F | yes | no |
Syntax Element Description:
Syntax Element | Description |
---|---|
operand1 |
Loop Control Variable
(
operand1 ) and Initial Setting
(operand2 ): The loop control variable value may be referenced during the execution of the processing loop and will contain the current value of the loop control variable. |
operand2
|
|
operand3
|
TO Value:
The processing loop is terminated when
|
operand4
|
STEP Value:
The The compare operation will be adjusted to "less than"
or "greater than" depending on the sign of the |
(arithmetic-expression) |
Arithmetic Expression:
In place of
Note: |
END-FOR
|
End of FOR Statement:
The Natural reserved word |
** 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.