·
The RPGLE statements which are to be iterated are placed
inside the block created by two opcodes DoW and EndDo.
·
The EndDo represents
the end of DoW block.
·
The RPGLE statements inside these opcodes are iterated till
the condition remains true.
·
The looping condition is specified as factor2 of the DoW
opcode.
·
The looping condition is checked at the beginning before any
iteration begins. If the condition is not true it doesn’t enter the loop even a
single time.
Factor 1
|
Op-code
|
Factor 2
|
Result Field
|
Resulting Indicators
HI LO EQ
|
|
DOW
|
Loop expression
|
|
|
|
|
Example
DCount S 2P 0 Inz
**
C DoW Count < 6
C Count Dsply
C Eval Count = Count + 1
C EndDo
**
C Return
OUTPUT
DSPLY 0
DSPLY 1
DSPLY 2
DSPLY 3
DSPLY 4
DSPLY 5
Ü DOW Versus DOU
DOW -- Do While -- does the statements in the DO-group while the
condition is true. The logical test for the condition happens at the DOW
statement, i.e., at the beginning. This implies that the statements won't be
executed at all if the condition is false at the time the DOW statement is
executed.
DOU -- Do Until -- does the statements in the DO-group until the
condition is true. The logical test for the condition happens at the ENDDO
statement. This implies that the statements will always be executed at least
once when the DO-group is reached.