Inline Perform with Test Before Until
Inline Perform with Test Before Until Example
Scenario - Displaying loop iterations using inline PERFORM...WITH TEST BEFORE UNTIL.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. PERFWTBU.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-I PIC 9(01) VALUE 1.
PROCEDURE DIVISION.
DISPLAY "Before PERFORM WITH TEST AFTER UNTIL".
PERFORM WITH TEST BEFORE UNTIL WS-I = 1
DISPLAY "WS-I: " WS-I
END-PERFORM.
DISPLAY "After PERFORM WITH TEST AFTER UNTIL".
STOP RUN.
Output -
Before PERFORM WITH TEST AFTER UNTIL After PERFORM WITH TEST AFTER UNTIL
Explaining Example -
In the above example:
- The condition is validated before executing the satements in the loop. If the condition true, the loop gets executed. Otherwise, loop gets terminated.