This code has an infinite loop. Find and fix it:
PERFORM VARYING WS-I FROM 1 BY 1
UNTIL WS-I = 10
DISPLAY WS-I
END-PERFORM.
Fix the Infinite Loop
Problem Description
Expected Output
Should print 1-9 and stop
Hints
Check the UNTIL condition carefully.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. FIXLOOP.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-I PIC 99.
PROCEDURE DIVISION.
* FIXED: Changed = to > for proper termination
PERFORM VARYING WS-I FROM 1 BY 1
UNTIL WS-I > 10
DISPLAY WS-I
END-PERFORM.
STOP RUN.
Explanation:
BUG: UNTIL WS-I = 10 might skip exact match. FIX: Use > for safety.