Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Difference between ELSE IF and ELSEIF

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Difference between ELSE IF and ELSEIF
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject: regaring that if construct
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    Post subject:
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    Post subject:
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    Post subject: HI ashishsawhney
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm
No new posts Sticky: difference between ... DUMMY ... and ... enrico-sorichetti JCL & VSAM 0 Mon Oct 17, 2016 4:31 pm
No new posts Difference space showed for TS and it... autobox DB2 1 Thu Apr 14, 2016 1:07 pm
No new posts Difference Between CICS WebSupport an... sachinji84 CICS 1 Mon Mar 07, 2016 7:25 pm
No new posts Difference between -180 and -181 with... deepak_shrivastava DB2 4 Wed Jan 06, 2016 10:00 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us