The DO statement groups statements into a single block. An END statement ends the DO block.

The DO block can be a simple non-iterating block, or you can use it to iterate. There are two ways you can control iteration in a DO block:
  • Iterate a specified number of times
  • Iterate while a condition is true

Iterate a specified number of times

To iterate for a specified number of times, you provide a starting and ending integer value for the iteration. By default, the iteration value increments by 1 at the end of each iteration. Optionally, you can provide a different increment or decrement value using the BY clause. The iteration ends when the ending value is reached. This is the basic syntax for using DO to iterate a specified number of times:

DO iteration-variable = starting-value to ending-value [BY increment-value]:
  <ABL statements>
end.

The following is an example

VAR INT ix.

DO ix = 1 TO 10:
  MESSAGE "The value of ix is" ix.
END.
Running the code produces the following output:
The value of ix is 1
The value of ix is 2
The value of ix is 3
The value of ix is 4
The value of ix is 5
The value of ix is 6
The value of ix is 7
The value of ix is 8
The value of ix is 9
The value of ix is 10

Iterate while a condition is true

You can also iterate while a condition is true by using the DO WHILE construct. The following is an example:

VAR INT ix.

ix = 10.

DO WHILE ix > 0:
  MESSAGE "The value of ix is" ix.
  ix = ix - 1.
END.
Running the code produces the following output:
The value of ix is 10
The value of ix is 9
The value of ix is 8
The value of ix is 7
The value of ix is 6
The value of ix is 5
The value of ix is 4
The value of ix is 3
The value of ix is 2
The value of ix is 1