Procedure Division and Control Structures
The Procedure Division domain tests control flow: how PERFORM executes paragraphs, how conditions and EVALUATE select paths, and how arithmetic and string statements report errors. Items often ask how many times a loop runs or where control resumes after an END-IF.
PERFORM forms
Out-of-line PERFORM names a paragraph or section; inline PERFORM contains statements ending with END-PERFORM. TIMES repeats a fixed count. UNTIL loops default to TEST BEFORE, so the condition is checked before the first execution; TEST AFTER executes at least once. VARYING combines initialization, increment and condition. PERFORM THRU executes every paragraph in the range, including paragraphs not named. A GO TO must not jump into the range of an active PERFORM.
Selection
IF/ELSE/END-IF nests cleanly only when scope terminators are present. EVALUATE TRUE selects on conditions; EVALUATE expression compares values; ALSO and ANY allow multiple subjects. WHEN OTHER is the fallback. CONTINUE is a no-op; NEXT SENTENCE jumps to the next period, which may be beyond END-IF, so CONTINUE is safer inside inline constructs.
Arithmetic and strings
COMPUTE supports ROUNDED and ON SIZE ERROR. ADD, SUBTRACT, MULTIPLY and DIVIDE have their own size-error handling. STRING and UNSTRING use POINTER and ON OVERFLOW. INSPECT performs TALLYING, REPLACING and CONVERTING. INITIALIZE sets numeric fields to zero and alphanumeric fields to spaces, respecting REPLACING. SET assigns 88 condition names and indexes.
Worked example. MOVE 0 TO TOTAL then PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5 with ADD I TO TOTAL inside runs five times and leaves TOTAL = 15, because TEST BEFORE checks I > 5 before each iteration. With TEST AFTER the loop runs six times and TOTAL = 21. After either loop I is 6, which matters if I is later used as a subscript.
Traps
- A period inside an IF closes the IF and every enclosing construct.
- Omitting END-PERFORM or END-IF and relying on paragraph layout.
- Confusing NEXT SENTENCE with CONTINUE in inline PERFORM or IF.
- Assuming PERFORM is recursive; recursion requires RECURSIVE and LOCAL-STORAGE.
- Applying ROUNDED to intermediate results rather than the final receiving field.