MainframeMaster

COBOL Tutorial

COBOL EXIT PARAGRAPH - Quick Reference

Progress0 of 0 lessons

Overview

The EXIT PARAGRAPH statement in COBOL is used to explicitly exit a paragraph and return control to the statement following the PERFORM that invoked it. It is rarely needed in modern structured COBOL, but can be useful for early returns in certain cases.

Purpose and Usage

  • Explicitly exit a paragraph before its natural end
  • Return control to the statement after the PERFORM
  • Rarely needed in structured code
  • Useful for early returns in complex logic

Syntax

The syntax for EXIT PARAGRAPH is simple:

Basic Syntax

cobol
1
EXIT PARAGRAPH.

Place EXIT PARAGRAPH where you want to leave the paragraph early.

Example: Early Return from Paragraph

cobol
1
2
3
4
5
PROCESS-RECORDS. IF NO-MORE-RECORDS EXIT PARAGRAPH. * ... more logic ... DISPLAY "Processing complete."

If NO-MORE-RECORDS is true, the paragraph exits early.

Example: With PERFORM

cobol
1
2
3
4
5
6
PERFORM PROCESS-RECORDS. ... PROCESS-RECORDS. IF ERROR-FOUND EXIT PARAGRAPH. * ... continue processing ...

EXIT PARAGRAPH returns control to the statement after the PERFORM.

Practical Examples

Here are some practical uses of EXIT PARAGRAPH in COBOL programs:

Early Exit for Validation

cobol
1
2
3
4
VALIDATE-INPUT. IF INVALID-DATA EXIT PARAGRAPH. * ... continue validation ...

Leaves the paragraph if data is invalid.

Complex Logic with Multiple Exits

cobol
1
2
3
4
5
6
PROCESS-DATA. IF ERROR-1 EXIT PARAGRAPH. IF ERROR-2 EXIT PARAGRAPH. * ... main processing ...

Multiple conditions can trigger early exit.

Best Practices

  • Use EXIT PARAGRAPH only when an early return is truly needed.
  • Prefer structured programming constructs (IF, PERFORM) for most control flow.
  • Avoid overusing EXIT PARAGRAPH, as it can make code harder to follow.
  • Document the reason for early exit when using EXIT PARAGRAPH.

Common Pitfalls

  • Using EXIT PARAGRAPH in a section or outside a paragraph (causes errors).
  • Relying on EXIT PARAGRAPH for normal control flow (prefer structured code).
  • Forgetting that most paragraphs end naturally without EXIT PARAGRAPH.

Test Your Knowledge

1. What is the primary purpose of the EXIT PARAGRAPH statement in COBOL?

  • To terminate the program
  • To exit from a paragraph and return control to the calling paragraph
  • To exit from a section
  • To skip to the next statement

2. Is EXIT PARAGRAPH required at the end of every paragraph?

  • Yes, always
  • No, it is optional and rarely needed
  • Only in the PROCEDURE DIVISION
  • Only for paragraphs with PERFORM

3. What happens if you use EXIT PARAGRAPH in a section?

  • It exits the section
  • It causes a compile error
  • It acts like EXIT SECTION
  • It skips to the next paragraph

4. What is the difference between EXIT PARAGRAPH and EXIT SECTION?

  • They are the same
  • EXIT PARAGRAPH exits a paragraph, EXIT SECTION exits a section
  • EXIT PARAGRAPH is obsolete
  • EXIT SECTION is for paragraphs only

5. When should you use EXIT PARAGRAPH?

  • To force an early return from a paragraph
  • At the end of every paragraph
  • To exit a loop
  • To terminate the program

Frequently Asked Questions