This iteration changes a value from a starting point to an end, optionally by a specified value for each step. The default change is 1.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 10 TO 15:
DISPLAY i WITH FRAME x1 6 DOWN .
DOWN WITH FRAME x1.
END.
Result:
---------------i
10
11
12
13
14
15
You can iterate over dates as well:
DEFINE VARIABLE dat AS INTEGER NO-UNDO.
DO dat = TODAY TO TODAY + 3:
END.
And over decimals. But then you most likely want to use BY
- otherwise an INTEGER
would have done just as fine...
DEFINE VARIABLE de AS DECIMAL NO-UNDO.
DO de = 1.8 TO 2.6 BY 0.2:
DISPLAY "Value" de.
END.
Using BY
a negative number you can also go from a higher to a lower value:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 5 TO 1 BY -1:
END.
The expression will be tested until it's no longer met. This makes the counter be higher (if moving upwards) or lower (if moving downwards) once the loop is finished:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 5 TO 1 BY -1:
END.
MESSAGE i. // Will message 0
Another example:
DEFINE VARIABLE da AS DATE NO-UNDO.
DISPLAY TODAY. //17/02/06
DO da = TODAY TO TODAY + 10:
END.
DISPLAY da. //17/02/17 (TODAY + 11)