| FORoperand1 |  |  
                              																		[:]=  |   |  |  | |||||
|   |  
                              																		 |  |  |  | ||||||
| 
 | STEP |  |  | 
 | ||||||
| statement   | ||||||||||
| END-FOR | (structured mode only) | |||||||||
| LOOP | (reporting mode only) | |||||||||
This document covers the following topics:
For explanations 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 | |||||||||||
| arithmetic-expression | S | N | P | I | F | no | no | |||||||||||||
| operand3 | C | S | N | N | P | I | F | yes | no | |||||||||||
| operand4 | C | S | N | N | P | I | F | yes | no | |||||||||||
Syntax Element Description:
| Syntax Element | Description | 
|---|---|
| operand1 |  Loop Control Variable
                                 																				( operand1) and Initial Setting
                                 																				(operand2):  The value specified after the keyword  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. Note: | 
| operand2 | |
| operand3 |  TO Value:  The processing loop is terminated when
                              																				 Note: | 
| STEP operand4 |  STEP Value:  The  The compare operation will be adjusted to "less
                              																				than" or "greater than" depending on the sign of the
                              																				 Notes: 
 | 
| (arithmetic-expression) | Arithmetic Expression: In place of
                              																				 Notes: 
 For further information on arithmetic expressions, see
                              																				 | 
| END-FOR | End of FOR Statement: In structured mode, the Natural reserved word
                              																				 In reporting mode, the Natural statement
                              																				 | 
| LOOP | 
** 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.