DOU (do until) is used for loops that should run until its conditions are meet.
ENDDO or END is used to define the end of the group of operations within the loop.
The condition is evaluated AFTER a run in the loop. That means it will always perform at least one iteration,
regardless if the conditions is met or not.
Example
1 2 3 4 5 6 7 8 |
dcl-s i int inz(0); dou i >= 10; i += 1; dsply 'This is loop number ' + %char(i); enddo; // For each loop, until i has reached 10, 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 10 11 12 |
D i 3I 0 D Message 52A * C Z-Add *Zero i * C Dou i >= 10 C Add 1 i C Eval Message = 'This is loop number ' + %char(i) C Message Dsply C EndDo * * For each loop, until i has reached 10, will the text "This is loop number nn" be shown on the screen where the nn is the number of the loop |