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.
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.
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 outputcobol
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
You predicted
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.
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?
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'.