Inline Perform with Test After Until
Inline Perform with Test After Until Example
Scenario - Displaying loop iterations using inline PERFORM...WITH TEST AFTER UNTIL.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. PERFWTAU.
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 WITH TEST AFTER UNTIL WS-I = 1
DISPLAY "WS-I: " WS-I
END-PERFORM.
DISPLAY "After Inline PERFORM WITH TEST AFTER UNTIL".
STOP RUN.
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.