|
Hello Adam, Here is what I remember learning in collage about the difference between Nested If's and a Case statements. Case is easier to read -- but it evaluates the entire statement. Nested If's are harder to read, but if the condition of the first statement is meet then it does not evaluate the rest of the If's. Now, this was 20 years ago and performance was a big concern. I guess everyone is going for readability now. That is my two cents. -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of rpg400-l-request@xxxxxxxxxxxx Sent: Thursday, May 25, 2006 2:24 PM To: rpg400-l@xxxxxxxxxxxx Subject: RPG400-L Digest, Vol 5, Issue 636 Send RPG400-L mailing list submissions to rpg400-l@xxxxxxxxxxxx To subscribe or unsubscribe via the World Wide Web, visit http://lists.midrange.com/mailman/listinfo/rpg400-l or, via email, send a message with subject or body 'help' to rpg400-l-request@xxxxxxxxxxxx You can reach the person managing the list at rpg400-l-owner@xxxxxxxxxxxx When replying, please edit your Subject line so it is more specific than "Re: Contents of RPG400-L digest..." *** NOTE: When replying to this digest message, PLEASE remove all text unrelated to your reply and change the subject line so it is meaningful. Today's Topics: 1. RE: Having both if/else executing at the same time (Willie J. Moore) 2. RE: Having both if/else executing at the same time (AGlauser@xxxxxxxxxxxx) 3. RE: Having both if/else executing at the same time (Rex Capio) 4. RE: Having both if/else executing at the same time (Michael_Schutte@xxxxxxxxxxxx) ---------------------------------------------------------------------- message: 1 date: Thu, 25 May 2006 12:50:23 -0700 from: "Willie J. Moore" <WMoore@xxxxxxxxxxxxxxx> subject: RE: Having both if/else executing at the same time Joe, Tried it 'elseif'. That did not work. Then put it back the way it was and low and behold it worked. We have compaired the two codes and they look the same. I would like to think everyone for there help and comments. Willie... -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of AGlauser@xxxxxxxxxxxx Sent: Thursday, May 25, 2006 12: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 ######################################################################## #############
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.