|
Tommy, Your example doesn't compare SELECT/WHEN and IF/ELSEIF. It doesn't include an ELSE or ELSEIF. Your IF/ENDIF groups are intended to execute either TWO of the THREE options or NONE of them. If (A) , DO (A stuff) AND (A or B stuff) If (B) , DO (B stuff) AND (A or B stuff) IF (not A) and (not B) , DO nothing. SELECT/WHEN and IF/ELSEIF are functionally the same because both are used when you want to execute ONLY ONE of the options at most. Making it the first WHEN means that the (A only stuff) and (B only stuff) wouldn't execute either. This would be the SELECT/WHEN equivalent to you IF/ENDIF groups. select; when A; // do A stuff // do A or B stuff when B; // do B stuff // do A or B stuff endsl; James |---------+------------------------------------------------> | | "Holden Tommy" | | | <Tommy.Holden@xxxxxxxxxxxxxxxxx> | | | Sent by: | | | rpg400-l-bounces+jamesmorey=pvh.com@m| | | idrange.com | | | | | | | | | 05/25/2006 03:48 PM | | | Please respond to RPG programming on | | | the AS400 / iSeries | | | | |---------+------------------------------------------------> >-----------------------------------------------------------------------------------------------| | | | To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx> | | cc: | | Subject: RE: Having both if/else executing at the same time | >-----------------------------------------------------------------------------------------------| The only significant difference that I am aware of between if/elseif & select/when is this: In This example, each if is evaluated at run-time: if (A) // do A stuff endif; if (B); // do B stuff endif; if ((A OR B)); // do A or B stuff endif; With select the when is evaluated until it finds the first match & skips the rest of the checks So in this example the "when A or B" would never be execute since an matching true expression has already occurred. select; when A; // do A stuff when B; // do B stuff leave; when A or B; //do A or B stuff other; // some sort of error endsl; Thanks, Tommy Holden -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of AGlauser@xxxxxxxxxxxx Sent: Thursday, May 25, 2006 2:36 PM To: RPG programming on the AS400 / iSeries Subject: RE: Having both if/else executing at the same time Willie, Have you stepped through the code? Any new information to pass on? Joe, I'm interested in your reasons for using select/when over if/elseif. I think I prefer if/elseif only because I learned about them first, and to me case-like statements should fall through like they do in C. It seems redundant to me to have both structures behave identically, and awkward to have to do: if (A) // do A stuff endif; if (B); // do B stuff endif; if (NOT (A OR B)); // some sort of error endif; when what I'd like to do is: select; when A; // do A stuff when B; // do B stuff leave; other; // some sort of error endsl; I realize that you're not advocating one method over the other, but I've heard people say that it is 'better' to use select/when instead of if/elseif, but they never provide any good reasons. Do you have any, or does it just feel more natural the way if/elseif does to me? Adam rpg400-l-bounces@xxxxxxxxxxxx wrote on 25/05/2006 02:53:47 PM: > Actually, the original code simply selected among three mutually exclusive > conditions. Using an ELSEIF doesn't change the outcome at all. > > IF CondA; > DoA; > ELSE; > IF CondB; > DoB; > ELSE; > DoC; > ENDIF; > ENDIF; > > Is functionally equivalent to: > > IF CondA; > DoA; > ELSEIF CondB; > DoB; > ELSE; > DoC; > ENDIF; > > The ELSEIF just removes the second "endif" (which you accidentally left in > your post, Bob, LOL!). This is also functionally equivalent to: > > SELECT; > WHEN CondA; > DoA; > WHEN CondB; > DoB; > OTHER; > DoC; > ENDSL; > > Nowadays I tend towards the third form if there are more than two mutually > exclusive conditions. > > It should be noted that the three conditions being selected among are > (CondA), ((NOT CondA) and (CondB)), and finally ((NOT CondA) and (NOT > CondB)). That is, even if both CondA and CondB are true, only the first > branch of the code will be executed. > > Joe > > > > From: Bob Cozzi > > > > ELSE and IF are two statements. In your code the only time the second IF > > will be > > performed is when the first IF fails. Why? Because the first ELSE is only > > going > > to be run if the first IF fails. Otherwise it'll jump to the ENDIF > > statements. > > I think what you really mean to have is ELSEIF not "ELSE" and "IF". > > Replace the ELSE and IF with ELSEIF, and then take a look as this page: > > > > www.rpgiv.com/blueribbon.html > > > > if %len(%trim(APIErrMsg)) > 0; > > W#ERFL = *ON; > > W#MSDT = 'Error #' + APIErrMsg + ' receiving data from ' + > > 'data queue. Detail: ' + APIErrDta; > > elseif %trim(itmInfo) = ''; > > W#ERFL = *ON; > > W#MSDT = 'Invalid data received from data queue: ' + > > itmInfo ; > > else; > > uMATNO = jMATNO; > > uSIZE = jSIZE; > > uTEMPER = jTEMPER; > > uINSUL = jINSUL; > > uTENSIL = jTENSIL; > > endif; > > endif; > > > -- > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list > To post a message email: RPG400-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/rpg400-l > or email: RPG400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/rpg400-l. > ######################################################################## ############# Attention: The above message and/or attachment(s) is private and confidential and is intended only for the people for which it is addressed. If you are not named in the address fields, ignore the contents and delete all the material. Thank you. Have a nice day. For more information on email virus scanning, security and content management, please contact administrator@xxxxxxxxxxxx ######################################################################## ############# -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.