EXIT in COBOL.

All sort of Mainframes Interview Questions.
Post Reply
B Sarkar
New Member
Posts: 1
Joined: Wed Dec 03, 2014 11:01 am

EXIT in COBOL.

Post by B Sarkar »

Hi,

What does EXIT do in COBOL?

My answer: I said, it does nothing.

I read this answer in one of the preparation material but interviewer was not happy with answer. Even after searching I still get the same answer that it does nothing and if it used it must be the only statement in the paragraph.

My question is, if it does nothing then why do we use it? Or can there be a better answer to the original question?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: EXIT in COBOL.

Post by Robert Sample »

The EXIT statement in a paragraph is most commonly used to mark the end of a PERFORM range (PERFORM A THRU B -- B would be the EXIT paragraph). As such, the EXIT behaves as a CONTINUE statement. However, since the PERFORM exit has some associated code, inadvertently falling into an EXIT paragraph without the PERFORM being active can cause various ABEND situations (storage and operation probably being the most common).
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: EXIT in COBOL.

Post by William Collins »

EXIT does nothing. CONTINUE does nothing. EXIT and CONTINUE are interchangeable.

That is, these days.

EXIT used to do nothing in a different way. It used to have to be in a paragraph of its own. Where it did nothing. At that time (prior to the 1985 COBOL Standard) CONTINUE did not exist.

However, people didn't generally think that EXIT did nothing. So, generally people thought (and many still think) that EXIT does something.

So you are correct. It does nothing. But some/many people think it does something. Many people who use PERFORM ... THRU ... believe it is necessary to have an EXIT.

Despite doing nothing, does it have any magic powers? Partly. If you look at a compile listing, you'll see there will always be code associated with an EXIT statement, apparently. How does that work? Well, the EXIT has just been used as a "label" to attach some compiler-generated code to. Without the exit, the identical code would be generated, and would appear to be attached to the previous verb to the following paragraph.

That little piece of magic, along with unchallenged misconceptions, leads people to believe EXIT does something. If something feels that way, and they happen to be interviewing you, it can be tricky :-)

Find all the "it does nothing" commentaries and collect together the "but people think..." parts. Post them here, and maybe we can polish someting up...
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”