FOR is used to setup a loop where an index can be set and changed by the setting on the FOR conditions.
ENDFOR or END is used to define the end of the group of operations within the loop.
The starting value of the index is set via an assignment on the FOR row.
BY can be used to set an incremental value. The default value is 1.
TO or DOWNTO is set to define if the incrementation should go up or down and to define what value the index should have to end the loop.
Example
1 2 3 4 5 6 |
dcl-s i int; for i = 1 by 1 to 10; dsply 'This is loop number ' + %char(i); endfor; // For each loop, 10 of them, will the text "This is loop number nn" be shown on the screen where the nn is the number of the loop |
Example RPGIV Fixed Format
1 2 3 4 5 6 7 8 9 |
D Message 52A D i 3P 0 * C For i = 1 by 1 to 10 C Eval Message = 'This is loop number ' + %Char(i) C Message Dsply C EndFor * * For each loop, 10 of them, will the text "This is loop number nn" be shown on the screen where the nn is the number of the loop |