View previous topic :: View next topic
|
Author |
Message |
ashishsawhney
New User
Joined: 21 Feb 2005 Posts: 3
|
|
|
|
What is the difference between these two pieces of code:--
CODE A
Code: |
IF CASE = 1
PERFORM X
ELSE
IF CASE = 2
PERFORM Y
ELSE
IF CASE = 3
PERFORM Z
ELSE
PERFORM DEFAULT-ROUTINE
END-IF
END-IF
END-IF
|
CODE B
Code: |
IF CASE = 1
PERFORM X
ELSE IF CASE = 2
PERFORM Y
ELSE IF CASE = 3
PERFORM Z
ELSE
PERFORM DEFAULT-ROUTINE
END-IF
|
as you can see there are 3 END-IF in CODE A and only one END-IF in CODE B ... so my question is how does the COBOL compiler know about it? |
|
Back to top |
|
|
sunnyk
New User
Joined: 20 Oct 2004 Posts: 59
|
|
|
|
Hi,
In any case( code A or CODE B) only one condition will be true at a time.Right!!.So it will look for an END-IF of the satisfied IF condition which IS TRUE.Like if CASE=1,it will "PERFORM X" and come out of the loop looking for END-IF.
So even if you give one END-IF instead of three,there won`t be any problem as ur CODE B suggests.
ANY UPDATES WELCOME.
Thanx
Sunny |
|
Back to top |
|
|
ashishsawhney
New User
Joined: 21 Feb 2005 Posts: 3
|
|
|
|
but then what is the need of coding three end-if if the problem is geeting solve by coding only one....
secondly, i m interested in finding...how do a cobol compiler look in this two very codes....seperately?????
well thanks for ur quick reply |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
I don't have access to a CPU but I'd say that code B won't compile unless perhaps it's terminated by a period.
Putting the IF on the same line as the ELSE doesn't change the code presented in code A. With the exception of the missing END-IFs they are identical. COBOL "squeezes" out the extra spaces during interpretation. |
|
Back to top |
|
|
sunnyk
New User
Joined: 20 Oct 2004 Posts: 59
|
|
|
|
Hi Jack,
Thats not the case.Even without a period,it will compile successfully.I tried that.
So any suggestions please add.
Thanks
sunny |
|
Back to top |
|
|
ramesh_chirumamillait
New User
Joined: 19 Feb 2005 Posts: 1 Location: nill
|
|
|
|
here the answer is correct but eventhough the compiler give the error.because for every if construct corresponding end-if has to be there.
so i think it will be error .compulsary there will be three end-ifs has to be there.....
ramesh.ch |
|
Back to top |
|
|
sunnyk
New User
Joined: 20 Oct 2004 Posts: 59
|
|
|
|
No dear...try that out on your own.PLEASE.It will work fine with one END-IF also anf with no period after END-IF too. |
|
Back to top |
|
|
muthukumarapandian
New User
Joined: 08 Oct 2004 Posts: 42 Location: chennai, india
|
|
|
|
Hi,
it will work well one scope terminator is enough for this program. |
|
Back to top |
|
|
madhusudhana
New User
Joined: 04 Mar 2005 Posts: 3 Location: bangalore
|
|
|
|
if your are using tyree IF statements there is no need to give three END-IF statements one is enough. and at final you give PERIOD. YOU WON;T get any compilation error. try this. |
|
Back to top |
|
|
Arun Joseph
New User
Joined: 30 Mar 2005 Posts: 13 Location: India
|
|
|
|
I think the requerement of a period as scope terminator depends on the COBOL version. Like VS-Cobol, OS/370 and OS/390. So try it depending on the COBOL version |
|
Back to top |
|
|
|