IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference between ELSE IF and ELSEIF


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ashishsawhney

New User


Joined: 21 Feb 2005
Posts: 3

PostPosted: Mon Feb 21, 2005 3:12 pm
Reply with quote

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
View user's profile Send private message
sunnyk

New User


Joined: 20 Oct 2004
Posts: 59

PostPosted: Mon Feb 21, 2005 5:18 pm
Reply with quote

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
View user's profile Send private message
ashishsawhney

New User


Joined: 21 Feb 2005
Posts: 3

PostPosted: Mon Feb 21, 2005 5:47 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Feb 21, 2005 7:56 pm
Reply with quote

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
View user's profile Send private message
sunnyk

New User


Joined: 20 Oct 2004
Posts: 59

PostPosted: Mon Feb 21, 2005 9:20 pm
Reply with quote

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
View user's profile Send private message
ramesh_chirumamillait

New User


Joined: 19 Feb 2005
Posts: 1
Location: nill

PostPosted: Mon Feb 21, 2005 9:21 pm
Reply with quote

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
View user's profile Send private message
sunnyk

New User


Joined: 20 Oct 2004
Posts: 59

PostPosted: Mon Feb 21, 2005 11:01 pm
Reply with quote

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
View user's profile Send private message
muthukumarapandian

New User


Joined: 08 Oct 2004
Posts: 42
Location: chennai, india

PostPosted: Sun Feb 27, 2005 5:16 pm
Reply with quote

Hi,

it will work well one scope terminator is enough for this program.
Back to top
View user's profile Send private message
madhusudhana

New User


Joined: 04 Mar 2005
Posts: 3
Location: bangalore

PostPosted: Mon Mar 07, 2005 4:42 pm
Reply with quote

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
View user's profile Send private message
Arun Joseph

New User


Joined: 30 Mar 2005
Posts: 13
Location: India

PostPosted: Wed Mar 30, 2005 9:14 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Timestamp difference and its average ... DB2 11
No new posts Difference when accessing dataset in ... JCL & VSAM 7
No new posts What is the difference between Taskty... Compuware & Other Tools 2
No new posts Difference between VALIDPROC and CHEC... DB2 3
No new posts Difference between CEE3250C and CEE3204S COBOL Programming 2
Search our Forums:

Back to Top