Looping, or iteration, is one of the automatic processing services that OpenEdge provides for blocks. REPEAT blocks and FOR EACH blocks iterate automatically. The following code fragments show iterations using these block statements:
/* This REPEAT block loops through its statements until the user
presses the END-ERROR (F4) key. */
REPEAT:
PROMPT-FOR customer.cust-num.
FIND customer USING cust-num.
DISPLAY customer WITH 2 COLUMNS.
END.
/* This FOR EACH block reads the records from the customer
table one at a time, processing the statements in the
block for each of those records. */
FOR EACH customer:
DISPLAY customer WITH 2 COLUMNS.
END.
/* This block loops through its statements for the first 5 customers. */
DEFINE VARIABLE i AS INTEGER.
DO i = 1 TO 5:
FIND NEXT customer.
DISPLAY customer WITH 2 COLUMNS.
END.