Outline Perform with Test After Until
Outline Perform with Test After Until Example
Scenario - Displaying loop iterations using outline PERFORM...WITH TEST AFTER UNTIL.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. PEROWTAU.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-I PIC 9(01) VALUE 1.
PROCEDURE DIVISION.
DISPLAY "Before Inline PERFORM WITH TEST AFTER UNTIL".
PERFORM 1000-ITERATION
THRU 1000-EXIT
WITH TEST AFTER UNTIL WS-I = 1.
DISPLAY "After Inline PERFORM WITH TEST AFTER UNTIL".
STOP RUN.
1000-ITERATION.
DISPLAY "WS-I: " WS-I.
1000-EXIT.
EXIT.
Output -
Before Inline PERFORM WITH TEST AFTER UNTIL WS-I: 1 After Inline PERFORM WITH TEST AFTER UNTIL
Explaining Example -
In the above example:
- The statements in the loop gets executed once, and then the condition is validated. So, we have a display "Iteration: " once even though the condition is true for the first time.