View previous topic :: View next topic
|
Author |
Message |
venosol Warnings : 1 New User
Joined: 16 Nov 2006 Posts: 43 Location: Bangalore
|
|
|
|
What will the exit do?
Everyone says that exit will do nothing. Then what's use of that.
Suppose if use exit in Nested If loop. After encountering the exit satement the control comes out of the loop ?
Please clarify on this. |
|
Back to top |
|
|
vicky10001 Warnings : 1 Active User
Joined: 13 Jul 2005 Posts: 136
|
|
|
|
The EXIT statement must be preceded by a paragraph-name and
must appear in a sentence by itself.
If an EXIT paragraph is specified as the last paragraph in a series of
performed paragraphs (i.e., PERFORM THRU), then it identifies the end
of the series of performed paragraphs. When control reaches an EXIT paragraph and such a PERFORM THRU is active, control is transferred
back to the statement following the PERFORM THRU.
When control reaches an EXIT paragraph that is not the end of a range
of paragraphs governed by an active PERFORM THRU, control passes
through the EXIT statement to the first statement of the following
paragraph.
The EXIT statement is also useful as an exit point for a single
performed paragraph, as shown below:
.
.
PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT.
.
1000-CALCULATE-TOTALS.
ADD 1 TO TOTAL-NUMBER-EMPS.
IF EMP-SALARY LESS THAN 25000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
IF EMP-SALARY LESS THAN 50000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
IF EMP-SALARY LESS THAN 75000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
1000-EXIT. EXIT. |
|
Back to top |
|
|
venosol Warnings : 1 New User
Joined: 16 Nov 2006 Posts: 43 Location: Bangalore
|
|
|
|
vicky10001 wrote: |
The EXIT statement must be preceded by a paragraph-name and
must appear in a sentence by itself.
If an EXIT paragraph is specified as the last paragraph in a series of
performed paragraphs (i.e., PERFORM THRU), then it identifies the end
of the series of performed paragraphs. When control reaches an EXIT paragraph and such a PERFORM THRU is active, control is transferred
back to the statement following the PERFORM THRU.
When control reaches an EXIT paragraph that is not the end of a range
of paragraphs governed by an active PERFORM THRU, control passes
through the EXIT statement to the first statement of the following
paragraph.
The EXIT statement is also useful as an exit point for a single
performed paragraph, as shown below:
.
.
PERFORM 1000-CALCULATE-TOTALS THRU 1000-EXIT.
.
1000-CALCULATE-TOTALS.
ADD 1 TO TOTAL-NUMBER-EMPS.
IF EMP-SALARY LESS THAN 25000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
IF EMP-SALARY LESS THAN 50000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
IF EMP-SALARY LESS THAN 75000
GO TO 1000-EXIT.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
1000-EXIT. EXIT. |
Consider the statements.
PERFORM 100-PARA THRU 500-PARA
100-PARA.
ADD 1 TO TOTAL-NUMBER-EMPS.
120-PARA.
ADD 1 TO EMPS-MAKING-25K-AND-UP.
520-PARA.
ADD 1 TO EMPS-MAKING-50K-AND-UP.
450-PARA.
ADD 1 TO EMPS-MAKING-75K-AND-UP.
500-PARA.
EXIT.
Now the control goes back to PERFORM. If we don't use the 500-PARA and we PERFORM 100-PARA THRU 450-PARA. Then also the control will go back to PERFORM after 450-PARA.
Now If I use 500-PARA AFTER 520-PARA. When control comes to exit statement it will go to 450-PARA which is a normal way.
In both the cases EXIT is not mandatory. Am I correct. Is there any other advantage.
My question is If I use in IF ELSE condition then how will be the execution. See the below example and clarify me.
IF X > 0
IF Y < 3
IF WS-COUNT = 20
EXIT
ELSE
DISPLAY ' I AM HERE'
END-IF
END-IF
END-IF |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Quote: |
My question is If I use in IF ELSE condition then how will be the execution. See the below example and clarify me. |
It will be trated as continue statement. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please refer to the prior replies quoting the manual. If you actually did what the quoted manual says you could not code:
Quote: |
IF X > 0
IF Y < 3
IF WS-COUNT = 20
EXIT
ELSE
DISPLAY ' I AM HERE'
END-IF
END-IF
END-IF
|
Your "EXIT" does not follow the rules above. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Dick,
It is allowed to code EXIT like the example mentioned above.
As I already stated, it will be trated as CONTINUE. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello Abhijit,
I've no doubt that it may "be gotten away with" - i do not believe it should be used. As the prior post showed from the Fine Manual, the only proper way to code an EXIT is to make it the only statement in a paragraph and it really has only one good use - to terminate a "perform thru".
There are many things we can get away with that we still should not use. If, in that example, a CONTINUE makes sense, a CONTINUE should be coded, not the mis-used EXIT. Think of some night a year or 2 later when there is a problem in that program and the person called to fix the problem is not the author (indeed, the author may not even work there any more) - how much time might they waste trying to figure out why that bit of potentially mis-leading code was in the program. . .
IMHO |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
I agree with you Dick on that. I never used EXIT like the example Venu gave us and will never need to. |
|
Back to top |
|
|
Josh_winkelstein
New User
Joined: 28 Mar 2007 Posts: 1 Location: Lansing MI USA
|
|
|
|
As previously noted, the EXIT statement is primarily or exclusively valid as a way to exit a PERFORM THRU structure.
A somewhat less obvious thing about this is that once you have reached the end of processing in the 9999-SOMETHING paragraph, you can GO TO the 9999-EXIT paragraph and still have a fully structured program. You can use this to skip any statements you know you don't have to execute if some condition is fulfilled, and thereby increase the efficiency of your code.
Unfortunately, the prohibition against the use of GO TO is often so strong that that the use of it in this situation, while valid and structured, will be denied or prohibited without any consideration. |
|
Back to top |
|
|
|