The REPEAT statement begins a block of ABL statements that are processed repeatedly until the block ends in one of several possible ways. You use an END statement to define the end of the block. REPEAT blocks can be explicitly terminated when runtime conditions, that you have specified in your code, occur. It is good programming practice to include a terminating condition to prevent infinite loops. REPEAT blocks are also useful for iterating over records.

Syntax

REPEAT ... :
  /* ABL statements */
END.

In the following example the WHILE phrase causes the REPEAT block to terminate after 100 iterations.

DEFINE VARIABLE ix AS INTEGER INITIAL 0 NO-UNDO.

REPEAT WHILE ix < 100:
  ix = ix + 1.
  DISPLAY ix.
END.
Running the code produces the following output (some output omitted for brevity):
        ix
----------
         1
         2
         3
         4
         5
       ...
        99
       100

In the following code a REPEAT block is used to iterate through database records.

REPEAT:
  FIND NEXT Customer.
  DISPLAY Customer.Name Customer.Balance.
END.

In the following example the REPEAT block is explicitly terminated:

REPEAT:
  FIND NEXT Customer.
  IF Customer.CustNum > 1000 THEN LEAVE.
  DISPLAY Customer.Name Customer.CustNum Customer.Balance.
END.