EXIT Statement


The EXIT statement is a "do-nothing" statement mainly used for readability and structure, giving a logical endpoint for a section or paragraph.

Syntax -

paragraph-name. 
    EXIT.

Notes -

The EXIT statement performs no operation when executed. It's usually used to -

  • Indicate the end of a paragraph that may be used as a logical exit or termination point for multiple paths in the program.
  • Mark the end of a section within the PROCEDURE DIVISION, mainly when the section is intended to contain multiple paragraphs but currently has none.

Using EXIT can improve the clarity and structure of the code, making it easier for other developers to understand the flow of the program.

Practical Example -


Scenario - EXIT usage in paragraph.

----+----1----+----2----+----3----+----4----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EXITPARA.
       AUTHOR. MTH.

       PROCEDURE DIVISION.
           PERFORM 1000-DISPLAY
              THRU 1000-EXIT.
           STOP RUN.

       1000-DISPLAY.
           DISPLAY "PARAGRAPH EXIT EXAMPLE". 
       1000-EXIT.
           EXIT.

Explaining example -

1000-EXIT is the paragraph coded only with EXIT statement that acts as a exit paragraph for 1000-DISPLAY.