PERFORM loops
| PERFORM TIMES | |
| PERFORM UNTIL | |
| PERFORM VARYING |
PERFORM TIMES
PERFORM n TIMES runs a sentence or paragraph a fixed number of times. Use it when the count is known before the loop starts:
PERFORM 5 TIMES
DISPLAY "Payroll run"
END-PERFORM.
PERFORM UNTIL
PERFORM UNTIL loops while a condition is false, and checks the condition before each pass. The counter must be set before the loop and advanced inside it:
MOVE 1 TO WS-I.
PERFORM UNTIL WS-I > 10
DISPLAY "Row " WS-I
ADD 1 TO WS-I
END-PERFORM.
PERFORM VARYING
PERFORM VARYING folds the counter into the loop itself. FROM sets the start, BY the step, and UNTIL the end condition:
PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 10
DISPLAY "Row " WS-I
END-PERFORM.
Next: Tables: OCCURS arrays
Article author: Arthur Isaev