Exercise 2: The Real Difference Between PERFORM UNTIL and PERFORM VARYING — Possible Solution ==================================================================== Both are genuinely real loops, but this chapter's own material describes them solving two different real problems - one built around an arbitrary condition, the other built specifically around counting. WHAT PERFORM UNTIL ACTUALLY DOES This chapter describes PERFORM UNTIL as COBOL's real conditional loop - it keeps repeating its body for as long as a stated condition remains false, with no built-in concept of counting iterations at all. This chapter's own worked example uses it to keep processing until a flag field reaches a specific value (WS-EOF-FLAG = "Y") - a condition that could, in principle, take any number of real passes to become true, depending entirely on external circumstances the loop itself doesn't track numerically. WHAT PERFORM VARYING ACTUALLY DOES This chapter describes PERFORM VARYING as COBOL's real counted loop - explicitly the closest equivalent to a for-loop in more modern languages - automatically increasing or decreasing a specific index value on each pass, using real FROM/BY/UNTIL clauses. This chapter's own worked example (PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 10) shows the index itself being tracked and incremented as a core, built- in part of the loop's own mechanism, not something the loop body has to manage manually. WHY THIS IS A GENUINE, PRACTICAL DIFFERENCE The real distinction is what's actually driving the loop's own termination. PERFORM UNTIL's ending condition can be anything at all - a flag set by file processing, a status check, any real Boolean expression - with no numeric counting built in. PERFORM VARYING's ending condition is specifically tied to a numeric index the statement itself manages, incrementing or decrementing it automatically each time through. WHEN YOU'D GENUINELY CHOOSE ONE OVER THE OTHER PERFORM VARYING is the natural real choice whenever the number of repetitions is itself the point - processing a specific range of index positions, for instance. PERFORM UNTIL is the natural real choice whenever the actual stopping condition has nothing to do with counting at all - such as this chapter's own real end-of-file flag example, where the loop needs to keep running until some external condition becomes true, regardless of how many passes that specific run happens to take. ANSWER: PERFORM UNTIL is a real conditional loop that keeps running until any stated condition becomes true, with no built-in counting - this chapter's own example uses it for an end-of-file flag check. PERFORM VARYING is a real counted loop that automatically manages a numeric index via FROM/BY/UNTIL, the closest COBOL equivalent to a for-loop - this chapter's own example uses it to step WS-I from 1 to 10. You'd choose PERFORM VARYING when the number of repetitions is the actual point of the loop, and PERFORM UNTIL when the real stopping condition is unrelated to counting, such as waiting for an external flag or status to change. WHY THIS WORKS AS AN ANSWER ------------------------------ This identifies the specific real mechanism each loop form is built around (arbitrary condition vs. managed numeric index), grounds the explanation in the chapter's own two worked examples, and gives a concrete, practical basis for choosing between them.