Control flow usually falls through statement by statement, but sometimes the remaining path should not run—end of file on GET in BEFORE-SCREEN, validation failure in a long PROC, error branch that must skip twenty setup lines. EXIT ends the current procedure invocation early: statements below EXIT in that PROC body are skipped for this PERFORM call, and control returns to the caller after the procedure module completes its return semantics. EXIT does not replace END-PROC in source; the module definition still closes with END-PROC after all possible paths including those below conditional EXIT. Beginners confuse EXIT with END-PROC, STOP, STOP RUN, and GOTO—each changes flow differently. STOP RUN terminates the program; GOTO jumps to a label; EXIT leaves one PROC call. This control-flow page teaches when early exit improves readability, BEFORE-SCREEN and sort BEFORE patterns, combining EXIT with IF, interaction with loops via PERFORM, contrast with RETURN in other contexts, and testing all PERFORM paths so skipped tail code never held required cleanup that must move before EXIT or into caller.
PERFORM transfers control into PROC module. Normal path executes all statements until implicit return at END-PROC boundary. EXIT shortcut jumps to return without executing intervening statements. Caller resumes after PERFORM. Multiple PERFORM paths may hit different EXIT points or fall through full body. Flow diagram shows EXIT as branch leaving PROC box early back to caller.
| Keyword | Scope | Control flow effect |
|---|---|---|
| EXIT | Current PROC invocation | Skip to procedure return |
| END-PROC | Module definition | Structural close; return if invoked |
| GOTO label | Activity containing label | Jump to label |
| STOP RUN | Program | Terminate run |
| RETURN | Context-specific | See RETURN page—screen/CALL contexts |
Screen cycle GET from master file: IF EOF, set message, EXIT—skip field MOVE and cursor setup that require valid record. Control returns to screen engine; END-PROC still ends module in source. Without EXIT, MOVE from empty buffer corrupts screen or abends. Same pattern in BEFORE procedures when prescreen determines record unusable—EXIT after error MESSAGE instead of running SELECT tail.
123456789BEFORE-SCREEN. PROC GET MASTER IF EOF MASTER MSG = 'NO MORE RECORDS' EXIT END-IF MOVE NAME TO SCR-NAME MOVE BAL TO SCR-BAL END-PROC
Guard clause style: IF invalid-condition, EXIT, END-IF at PROC top—main logic below assumes preconditions met. Reduces nesting versus IF valid ... large block END-IF. Limit stacked guard EXITs to three; beyond that use CASE or PERFORM sub-procs. Each guard EXIT must represent mutually exclusive failure mode documented in proc header comment.
Runtime EXIT skips statements; compile-time module still needs END-PROC after all statements including unreachable-on-EXIT tail if present in source. Tail after EXIT may hold shared cleanup—if cleanup must always run, place before EXIT or in caller after PERFORM. Confusing EXIT with END-PROC causes missing terminator compile errors when developer deletes END-PROC thinking EXIT closed module.
DO WHILE loop PERFORM SEARCH-PROC; inside SEARCH-PROC, EXIT when found—returns to loop body after PERFORM, loop continues unless caller sets FOUND and WHILE condition stops. EXIT does not break DO loop directly. Pattern: PERFORM sets FOUND Y, loop condition includes FOUND EQ N, or GOTO after END-DO in caller when PERFORM reports success via flag field.
Invalid record: EXIT without SELECT excludes from sort output and skips remaining BEFORE logic. Valid record: SELECT at end. IF error EXIT early avoids accidental SELECT in fall-through tail. Order IF validation, EXIT, processing, SELECT documents inclusion pipeline clearly.
EXIT is leaving the recipe early when you realize you are out of eggs. You stop reading the rest of that recipe card and go back to whoever asked you to cook. The recipe card still has an END at the bottom on the paper—you just did not do every step this time. You need another way to finish dinner if steps after EXIT were important.
1. EXIT in a PROC:
2. After EXIT in PROC control returns:
3. EXIT versus END-PROC:
4. BEFORE-SCREEN GET EOF often uses EXIT to:
5. EXIT does not replace: