CONTINUE, NEXT SENTENCE and Scope Terminators

COBOL GnuCOBOL 3.2.0 · ✓ verified by execution on 2026-08-16

When maintaining older COBOL codebases, you will inevitably encounter the keywords CONTINUE and NEXT SENTENCE, as well as a mix of END-IF and scattered periods (.).

Understanding how these elements control the scope of execution is one of the most critical skills for reading and debugging mainframe applications. It is a common trap in interviews and a frequent source of “dangling else” logic bugs.

Explicit vs Implicit Scope Terminators

In COBOL, you must signal to the compiler when a conditional statement (like IF or EVALUATE) is finished. You can do this explicitly or implicitly.

Explicit scope terminators consist of the word END followed by a hyphen and the name of the statement (e.g., END-IF). They cleanly close a specific block.

cobol ✓ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EX-ENDIF.
       PROCEDURE DIVISION.
           IF 1 = 1
               DISPLAY 'INSIDE'
           END-IF.
           DISPLAY 'OUTSIDE'.
           STOP RUN.
Output
INSIDE
OUTSIDE

Implicit scope terminators use a simple period (.). A period closes all open conditional statements that have not yet been explicitly terminated.

cobol ✓ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EX-DOT.
       PROCEDURE DIVISION.
           IF 1 = 1
               DISPLAY 'INSIDE'.
           DISPLAY 'OUTSIDE'.
           STOP RUN.
Output
INSIDE
OUTSIDE

The Nested IF Danger

Implicit terminators are dangerous when nesting logic. A single stray period will prematurely terminate all open blocks, severely breaking your logic.

cobol ✓ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EX-NEST.
       PROCEDURE DIVISION.
           IF 1 = 1
               IF 1 = 2
                   DISPLAY 'WRONG'
               END-IF
           ELSE
               DISPLAY 'ALSO WRONG'
           END-IF
           DISPLAY 'DONE'.
           STOP RUN.
Output
DONE

In the example above, the END-IF correctly links the ELSE to the outer IF. If you had used periods instead, the ELSE could attach to the inner IF, resulting in the infamous “dangling else” bug. Modern COBOL standards strongly recommend exclusively using explicit terminators (END-IF, END-EVALUATE, END-PERFORM) to prevent these issues.

CONTINUE vs NEXT SENTENCE

When writing stub code or empty branches, you need a placeholder statement that does nothing. COBOL offers two, but they behave radically differently.

CONTINUE: The Safe No-Op

CONTINUE is a pure no-operation statement. It does absolutely nothing and simply passes control to the next executable statement.

cobol ✓ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EX-CONT.
       PROCEDURE DIVISION.
           IF 1 = 1
               CONTINUE
           ELSE
               DISPLAY 'WRONG'
           END-IF.
           DISPLAY 'CONTINUE DID NOTHING'.
           STOP RUN.
Output
CONTINUE DID NOTHING

NEXT SENTENCE: The Dangerous Jump

NEXT SENTENCE is archaic and behaves like an invisible GO TO. It explicitly transfers control past the next separator period (.), skipping any statements that lie between the NEXT SENTENCE and that period.

Predict the output cobol

What is the final value of X?

       IDENTIFICATION DIVISION.
       PROGRAM-ID. EX-NEXT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 X PIC 9 VALUE 1.
       PROCEDURE DIVISION.
           IF X = 1
               NEXT SENTENCE
               ADD 1 TO X
           END-IF
           ADD 2 TO X.
           ADD 3 TO X.
           DISPLAY X.
           STOP RUN.
Output
4

Notice that both ADD 1 TO X and ADD 2 TO X were completely ignored! The execution jumped straight past the period that followed ADD 2 TO X., landing on ADD 3 TO X.

If there is no period, NEXT SENTENCE will fall right through to the end of the program, skipping everything along the way.

CONTINUE IF Condition CONTINUE END-IF Next Statement. NEXT SENTENCE IF Condition NEXT SENTENCE END-IF Next Statement. Statement After Period

Best Practice: Never use NEXT SENTENCE in new code. Always use CONTINUE when you need a no-op placeholder, and always use explicit scope terminators (END-IF) instead of periods to close your logical blocks.

Check yourself

What is the key difference between CONTINUE and NEXT SENTENCE?

Reveal answer

CONTINUE is a simple no-op that proceeds normally, while NEXT SENTENCE acts as a GOTO that jumps completely past the next separator period. — CONTINUE does nothing and simply passes control to the next physical statement (e.g., jumping out of the IF). NEXT SENTENCE physically searches the code for the next period (.) and jumps immediately after it.

Why is using explicit scope terminators (like END-IF) preferred over implicit scope terminators (like periods) in modern COBOL?

Reveal answer

Because explicit terminators clearly mark the end of specific blocks, preventing 'dangling else' bugs and unintended early termination of nested logic. — A single stray period will close ALL open conditional statements at once, often breaking complex nested logic. Explicit terminators like END-IF only close the exact block they are paired with.

If you have a NEXT SENTENCE statement but there are no periods before the end of the program, what happens?

Reveal answer

Control falls through to the end of the program, skipping all subsequent statements. — NEXT SENTENCE will literally bypass all statements until it finds a period. If the only period is at the very end of the division, it will skip everything else.

Challenges

Challenge 1 +25 XP

Fix this code so that it prints 'A' and 'C'. Do not change the display statements.

cobol ✓ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real — it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 — expects "A\nC\n"
Need a hint? (−25% XP)

NEXT SENTENCE skips past the period, meaning it skips DISPLAY 'A'. What statement does nothing but proceeds normally?

Show solution (0 XP)
IDENTIFICATION DIVISION.
PROGRAM-ID. CHAL-CONT.
PROCEDURE DIVISION.
    IF 1 = 1
        CONTINUE
    END-IF
    DISPLAY 'A'.
    DISPLAY 'C'.
    STOP RUN.

Challenge 2 +25 XP

Fix this code by replacing the dangerous period with an explicit scope terminator so that both 'A' and 'B' print.

cobol ✓ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real — it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 — expects "A\nB\n"
Need a hint? (−25% XP)

Use END-IF to close the IF statement and remove the period after DISPLAY 'A'.

Show solution (0 XP)
IDENTIFICATION DIVISION.
PROGRAM-ID. CHAL-ENDIF.
PROCEDURE DIVISION.
    IF 1 = 1
        DISPLAY 'A'
    END-IF.
    DISPLAY 'B'.
    STOP RUN.