DO Loops
- Last UpdatedOct 29, 2024
- 2 minute read
A do-loop enables a series of commands to be repeated more than once. The number of times the series is repeated is controlled by a counter.
Control is passed to the line following the enddo command after executing the commands within the loop with the counter variable at its final value.
The full format of the do-loop is as follows:
do !x from 10 to 100 by 10
!Total = !Total + !X
enddo
The enddo must be present at the end of the loop.
The !X , from, to and by are optional, therefore in its simplest form you may use:
do
commands block
enddo
This will loop forever unless something in the commands block stops the loop (see break and golabel below).
The elements of the loop are as follows:
|
Element |
Purpose |
|
!X |
A PML Local (or Global) variable that is automatically updated with the value of the loop-counter every time round the loop. If you do not supply a loop variable, a hidden unnamed variable will be used for the counter. Note: |
|
from |
Defines the value of the counter for the first time round the loop. If you do not give a value, it will default to 1. |
|
to |
Defines the value of the counter for the final time round the loop. The default is infinity. |
|
by |
Defines the step size (positive or negative) by which the counter value is changed each time round the loop. The default value is +1. |