I've seen many COBOL programs contain sections with at the end
XX-99.
EXIT.
Many times that paragraph is used to exit the section, for instance with GO TO XX-99
. I have read that EXIT
is a no-operation, as it doesn't do anything. But the same goes for CONTINUE
. One could easily replace EXIT
with CONTINUE
. Alternatively, one could replace GO TO XX-99
with EXIT SECTION
.
Is there any compelling reason to use EXIT
rather than CONTINUE
? Why was EXIT
introduced anyway? Was EXIT
introduced before CONTINUE
was?
Note: I'm not talking about EXIT
in combination with another reserved word, like EXIT PROGRAM
or EXIT PERFORM
.
Is there any compelling reason to use EXIT rather than CONTINUE?
Why was EXIT introduced anyway?
Was EXIT introduced before CONTINUE was?
There is no "compelling" reason to choose one over the other. There is no practical difference. The reason to choose EXIT
over CONTINUE
is conformance to existing coding standards.
EXIT
was part of the original COBOL 60 Report where it was a "Compiler Directing Verb." Its purpose was to mark the end of a performed procedure, directing the compiler to transfer control to the statement following the invoking PERFORM
statement or to the PERFORM
statement for the next iteration of a loop.
In the ANSI COBOL 68 standard, it became a statement to mark the end of a performed procedure. It was no longer required, since the end of the perform range was the end of the last (or only) performed paragraph or section. It remained as a convenient target for a GO TO
statement.
[With the introduction of the SORT
statement, an EXIT
statement may also be used to mark the end of an input or output procedure.]
CONTINUE
was introduced in the 1985 standard as part of the changes for structured programming. It purpose was to replace the NEXT SENTENCE
statement used within the IF
and SEARCH
statements or wherever an imperative statement is required by a statement format, but nothing need be done. It is in this last use that a CONTINUE
statement may be used to replace an EXIT
statement.
EXIT SECTION
was introduced in the 2002 standard.
The 2014 standard still says:
The
EXIT
statement provides a common end point for a series of procedures [...]
[it] shall appear in a sentence by itself that shall be the only sentence in the paragraph [...]
[and] serves only to enable the user to assign a procedure-name to a given point in a procedure division.
Such anEXIT
statement has no other effect on the compilation or execution.
Even in COBOL 202x this format it still is not marked archaic (while the EXIT PROGRAM
format is, because of the same functionality provided by GOBACK
).
With its different syntax rules to the CONTINUE
statement it is already not the same (though some COBOL compilers don't enforce this rule and some of those also don't have an option to even create a warning if this rule is broken).
Concerning the originating: COBOL-74 does not seem to have a CONTINUE
statement (at least my copy of VAX-11 COBOL-74 does not list it), it seems to have come in together with the inline format of the PERFORM
statement in COBOL-85.
I personally would also prefer the procedure format of EXIT
(EXIT SECTION
or even EXIT PARAGRAPH
if no sections are used in the program) over a GO TO
, but as always with COBOL: follow whatever your team-/house-rules are, some may also forbid those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With