Re: *** GMX Spamverdacht *** Re: [U2] DO/WHILE vs IF THEN
Why not something simple that works everywhere, like loop readnext id else exit ... repeat /Scott Ballinger Pareto Corporation Edmonds WA USA 206 713 6006 On Mon, Mar 30, 2009 at 12:01 AM, Mecki Foerthmann mec...@gmx.net wrote: have you tried LOOP WHILE READNEXT ID DO ? MAJ Programming wrote: LOOP WHILE READNEXT does not work on D3. Mark Johnson - Original Message - From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 7:38 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: *** GMX Spamverdacht *** Re: [U2] DO/WHILE vs IF THEN
That of course would most likely not compile on our UniData system, since unlike D3 it's case sensitive and I don't think it supports lower case Basic code. And if there is even a remote chance the code might be ported to D3 one day and you write it in upper case, you are right of course. But what about '3 more keystrokes and an extra line of code?' to answer your question. Up to now I actually thought the DO was required syntax and not just a throw-away, so from now on I'm going to save another 3 keystrokes :-) Scott Ballinger wrote: Why not something simple that works everywhere, like loop readnext id else exit ... repeat /Scott Ballinger Pareto Corporation Edmonds WA USA 206 713 6006 On Mon, Mar 30, 2009 at 12:01 AM, Mecki Foerthmann mec...@gmx.net wrote: have you tried LOOP WHILE READNEXT ID DO ? MAJ Programming wrote: LOOP WHILE READNEXT does not work on D3. Mark Johnson - Original Message - From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 7:38 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: *** GMX Spamverdacht *** Re: [U2] DO/WHILE vs IF THEN
have you tried LOOP WHILE READNEXT ID DO ? MAJ Programming wrote: LOOP WHILE READNEXT does not work on D3. Mark Johnson - Original Message - From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 7:38 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
Another 2 cents here. If not using a global input routine, I usually use this syntax: LOOP prompt, position cursor, whatever INPUT ANS ANS = UPCASE(ANS) or ANS = OCONV(ANS, 'MCU') if you don't have UPCASE UNTIL ANS MATCHES 'Y]N' DO ] is an actual value mark error message REPEAT Most programmers forget to upcase the input, which frustrates users who just popped back into your application window from Word, Excel or some other Windows program. What a simple thing to do to makes users really happy. Like it, don't like it, it's all the same to me. This thread has certainly shown that there are many ways to skin a cat, but no matter which one you pick, the cat's not going to like it very much. ;-) Best regards and Hi to some very familiar names I haven't corresponded with in a long time, Charlie Noah Inland Truck Parts Company On 3/6/2009 12:02 AM, MAJ Programming wrote: No offense but the FOR...NEXT example for this thread is fools folly. Not because it is wrong. It over complicates the original premise (that was deviated from the original thread. The deviation became ways to validate Y or N. Fair enough and the LOOP examples all participate in a validation pausing until Y or N is entered. But just because the expression can be written in another way, doesn't mean that it's a comparable replacement. In this case, IMHO, it is very distracting. FOR...NEXT sequences automatically imply some form of incrementing through something. Assumption? Yes. But it's 99.44% used for incrementing and not stalling as in your example. Thus, the next programmer who has to read this will be mentally following the code, processing the logic flow and when they see the validation area, they will have to look twice and see why a FOR...NEXT loop is used for validation. Sure, there are many valid ways to skin each cat. But this one is a poor example of validating a Y/N answer. My 2 cents, Mark Johnson PS. The INDEX(YN,ANS,1) has a slight problem as it allows the enter alone answer to pass as a valid answer. I use this all the time when I prompt IS THIS OKAY (Y/N/Enter=Y) :;INPUT ANS. But for a pure Y or N, the null value passes. - Original Message - From: Jacques G. jacque...@yahoo.com To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 8:46 PM Subject: Re: [U2] DO/WHILE vs IF THEN The case can be tested also if n/y are acceptable: LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 UNTIL INDEX('NY',UPCASE(ANS),1) REPEAT *-- P.AM will contain a boolean value 0 for N, 1 for Y --* FOR X = 1 TO (X+1) PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 FIND UPCASE(ANS) IN N:@AM:Y SETTING P.AM THEN P.AM -= 1 ; EXIT NEXT X - Original Message From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 2, 2009 7:38:16 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
One of the things I like about using CASE's After all the checks you think there should be are done, you can setup the CASE 1 (or CASE -1) section to get all those inputs that normal people wouldn't enter. George -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2- us...@listserver.u2ug.org] On Behalf Of Laurie Blain Sent: Monday, March 30, 2009 10:54 AM To: u2-users@listserver.u2ug.org Subject: Re: [U2] DO/WHILE vs IF THEN Another 2 cents I agree with Charlie. You have to think like an end user when you ask for input. At one time I even included a beep if the end user entered anything outside of range. Laurie Blain Unidata Programmer Analyst Live, Love, Code! 614-804-7237 Columbus, Ohio laurie_bl...@yahoo.com --- On Mon, 3/30/09, Charlie Noah cwn...@comcast.net wrote: From: Charlie Noah cwn...@comcast.net Subject: Re: [U2] DO/WHILE vs IF THEN To: u2-users@listserver.u2ug.org Date: Monday, March 30, 2009, 5:00 AM Another 2 cents here. If not using a global input routine, I usually use this syntax: LOOP prompt, position cursor, whatever INPUT ANS ANS = UPCASE(ANS) or ANS = OCONV(ANS, 'MCU') if you don't have UPCASE UNTIL ANS MATCHES 'Y]N' DO ] is an actual value mark error message REPEAT Most programmers forget to upcase the input, which frustrates users who just popped back into your application window from Word, Excel or some other Windows program. What a simple thing to do to makes users really happy. Like it, don't like it, it's all the same to me. This thread has certainly shown that there are many ways to skin a cat, but no matter which one you pick, the cat's not going to like it very much. ;-) Best regards and Hi to some very familiar names I haven't corresponded with in a long time, Charlie Noah Inland Truck Parts Company On 3/6/2009 12:02 AM, MAJ Programming wrote: No offense but the FOR...NEXT example for this thread is fools folly. Not because it is wrong. It over complicates the original premise (that was deviated from the original thread. The deviation became ways to validate Y or N. Fair enough and the LOOP examples all participate in a validation pausing until Y or N is entered. But just because the expression can be written in another way, doesn't mean that it's a comparable replacement. In this case, IMHO, it is very distracting. FOR...NEXT sequences automatically imply some form of incrementing through something. Assumption? Yes. But it's 99.44% used for incrementing and not stalling as in your example. Thus, the next programmer who has to read this will be mentally following the code, processing the logic flow and when they see the validation area, they will have to look twice and see why a FOR...NEXT loop is used for validation. Sure, there are many valid ways to skin each cat. But this one is a poor example of validating a Y/N answer. My 2 cents, Mark Johnson PS. The INDEX(YN,ANS,1) has a slight problem as it allows the enter alone answer to pass as a valid answer. I use this all the time when I prompt IS THIS OKAY (Y/N/Enter=Y) :;INPUT ANS. But for a pure Y or N, the null value passes. - Original Message - From: Jacques G. jacque...@yahoo.com To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 8:46 PM Subject: Re: [U2] DO/WHILE vs IF THEN The case can be tested also if n/y are acceptable: LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 UNTIL INDEX('NY',UPCASE(ANS),1) REPEAT *-- P.AM will contain a boolean value 0 for N, 1 for Y --* FOR X = 1 TO (X+1) PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 FIND UPCASE(ANS) IN N:@AM:Y SETTING P.AM THEN P.AM -= 1 ; EXIT NEXT X - Original Message From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 2, 2009 7:38:16 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org
Re: *** GMX Spamverdacht *** Re: [U2] DO/WHILE vs IF THEN
Yes. I straddle U2 systems as well as D3, Mvbase and a few natives. Each has their own advanced way of handling READNEXT. Mark - Original Message - From: Mecki Foerthmann mec...@gmx.net To: u2-users@listserver.u2ug.org Sent: Monday, March 30, 2009 2:01 AM Subject: Re: *** GMX Spamverdacht *** Re: [U2] DO/WHILE vs IF THEN have you tried LOOP WHILE READNEXT ID DO ? MAJ Programming wrote: LOOP WHILE READNEXT does not work on D3. Mark Johnson - Original Message - From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 7:38 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
I don't know all of the login parameters but one UV client of mine (on SCO) has a setting that allows the users to remain in lower case on the MS side of things (the more often case setting) and without hitting caps lock, going to UV it's all in upper case as their legacy app and data is (are?). Mark - Original Message - From: Charlie Noah cwn...@comcast.net To: u2-users@listserver.u2ug.org Sent: Monday, March 30, 2009 4:00 AM Subject: Re: [U2] DO/WHILE vs IF THEN Another 2 cents here. If not using a global input routine, I usually use this syntax: LOOP prompt, position cursor, whatever INPUT ANS ANS = UPCASE(ANS) or ANS = OCONV(ANS, 'MCU') if you don't have UPCASE UNTIL ANS MATCHES 'Y]N' DO ] is an actual value mark error message REPEAT Most programmers forget to upcase the input, which frustrates users who just popped back into your application window from Word, Excel or some other Windows program. What a simple thing to do to makes users really happy. Like it, don't like it, it's all the same to me. This thread has certainly shown that there are many ways to skin a cat, but no matter which one you pick, the cat's not going to like it very much. ;-) Best regards and Hi to some very familiar names I haven't corresponded with in a long time, Charlie Noah Inland Truck Parts Company On 3/6/2009 12:02 AM, MAJ Programming wrote: No offense but the FOR...NEXT example for this thread is fools folly. Not because it is wrong. It over complicates the original premise (that was deviated from the original thread. The deviation became ways to validate Y or N. Fair enough and the LOOP examples all participate in a validation pausing until Y or N is entered. But just because the expression can be written in another way, doesn't mean that it's a comparable replacement. In this case, IMHO, it is very distracting. FOR...NEXT sequences automatically imply some form of incrementing through something. Assumption? Yes. But it's 99.44% used for incrementing and not stalling as in your example. Thus, the next programmer who has to read this will be mentally following the code, processing the logic flow and when they see the validation area, they will have to look twice and see why a FOR...NEXT loop is used for validation. Sure, there are many valid ways to skin each cat. But this one is a poor example of validating a Y/N answer. My 2 cents, Mark Johnson PS. The INDEX(YN,ANS,1) has a slight problem as it allows the enter alone answer to pass as a valid answer. I use this all the time when I prompt IS THIS OKAY (Y/N/Enter=Y) :;INPUT ANS. But for a pure Y or N, the null value passes. - Original Message - From: Jacques G. jacque...@yahoo.com To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 8:46 PM Subject: Re: [U2] DO/WHILE vs IF THEN The case can be tested also if n/y are acceptable: LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 UNTIL INDEX('NY',UPCASE(ANS),1) REPEAT *-- P.AM will contain a boolean value 0 for N, 1 for Y --* FOR X = 1 TO (X+1) PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 FIND UPCASE(ANS) IN N:@AM:Y SETTING P.AM THEN P.AM -= 1 ; EXIT NEXT X - Original Message From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 2, 2009 7:38:16 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
LOOP WHILE READNEXT does not work on D3. Mark Johnson - Original Message - From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 7:38 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
No offense but the FOR...NEXT example for this thread is fools folly. Not because it is wrong. It over complicates the original premise (that was deviated from the original thread. The deviation became ways to validate Y or N. Fair enough and the LOOP examples all participate in a validation pausing until Y or N is entered. But just because the expression can be written in another way, doesn't mean that it's a comparable replacement. In this case, IMHO, it is very distracting. FOR...NEXT sequences automatically imply some form of incrementing through something. Assumption? Yes. But it's 99.44% used for incrementing and not stalling as in your example. Thus, the next programmer who has to read this will be mentally following the code, processing the logic flow and when they see the validation area, they will have to look twice and see why a FOR...NEXT loop is used for validation. Sure, there are many valid ways to skin each cat. But this one is a poor example of validating a Y/N answer. My 2 cents, Mark Johnson PS. The INDEX(YN,ANS,1) has a slight problem as it allows the enter alone answer to pass as a valid answer. I use this all the time when I prompt IS THIS OKAY (Y/N/Enter=Y) :;INPUT ANS. But for a pure Y or N, the null value passes. - Original Message - From: Jacques G. jacque...@yahoo.com To: u2-users@listserver.u2ug.org Sent: Monday, March 02, 2009 8:46 PM Subject: Re: [U2] DO/WHILE vs IF THEN The case can be tested also if n/y are acceptable: LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 UNTIL INDEX('NY',UPCASE(ANS),1) REPEAT *-- P.AM will contain a boolean value 0 for N, 1 for Y --* FOR X = 1 TO (X+1) PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 FIND UPCASE(ANS) IN N:@AM:Y SETTING P.AM THEN P.AM -= 1 ; EXIT NEXT X - Original Message From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 2, 2009 7:38:16 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
The case can be tested also if n/y are acceptable: LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 UNTIL INDEX('NY',UPCASE(ANS),1) REPEAT *-- P.AM will contain a boolean value 0 for N, 1 for Y --* FOR X = 1 TO (X+1) PRINT ENTER 'Y' OR 'N' :;INPUT ANS,1 FIND UPCASE(ANS) IN N:@AM:Y SETTING P.AM THEN P.AM -= 1 ; EXIT NEXT X - Original Message From: Keith Johnson [DATACOM] kei...@datacom.co.nz To: u2-users@listserver.u2ug.org Sent: Monday, March 2, 2009 7:38:16 PM Subject: Re: [U2] DO/WHILE vs IF THEN Mark Johnson suggested the following change Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT These forms all work (Universe 10.2.0) and are progressively shorter than the above LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N DO REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT LOOP PRINT ENTER 'Y' OR 'N' :;INPUT ANS UNTIL ANS=Y OR ANS=N REPEAT Ray Wurlod was a great proponent of the LOOP WHILE READNEXT ID format. I believe it may not compile on some MV systems. Regards, Keith --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
Hi George, Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT None at all. Use of WHILE/UNTIL is sometimes easier to read. Conversely, some exit conditions can only be done using EXIT if they are, for example, in some deeper conditional construct. First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Correct. The test is carried out at the point where you write it. A single loop can contain many WHILE/UNIT conditions scattered through it but uncontrolled use of this can make programs difficult to read. Martin Phillips Ladybridge Systems Ltd 17b Coldstream Lane, Hardingstone, Northampton, NN4 6DB +44-(0)1604-709200 --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
CTR =0 LOOP WHILE CTR 4 CTR+=1 PRINT CTR REPEAT FOR CTR = 0 TO 4 PRINT CTR NEXT CTR CTR = 0 LOOP CTR += 1 PRINT CTR IF CTR 4 THEN EXIT REPEAT If you're going to use a counter, might as well use a for loop. Your test didn't work because you didn't test the limit after each increment. Repeating the increment and print statement like your example does defeats the purpose of the loop. - Original Message From: George Gallen ggal...@wyanokegroup.com To: Ardent u2-users@listserver.u2ug.org Sent: Friday, February 27, 2009 11:20:15 AM Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
actually, my test did work. I was testing to see if the loop would end when the condition was met and it wasn't being tested directly. It was only a test, and not meant to be a counter loop, just that is was in a loop, and each increment after 3 was printed to show it was still inside the loop (which I expected, since it would only drop out of the loop when it hits the WHILE expression DO statement). George -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2- us...@listserver.u2ug.org] On Behalf Of Jacques G. Sent: Friday, February 27, 2009 12:16 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] DO/WHILE vs IF THEN CTR =0 LOOP WHILE CTR 4 CTR+=1 PRINT CTR REPEAT FOR CTR = 0 TO 4 PRINT CTR NEXT CTR CTR = 0 LOOP CTR += 1 PRINT CTR IF CTR 4 THEN EXIT REPEAT If you're going to use a counter, might as well use a for loop. Your test didn't work because you didn't test the limit after each increment. Repeating the increment and print statement like your example does defeats the purpose of the loop. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
George, In my opinion you lose the elegance and readability of the LOOP construct when you use EXIT. Code is easier to debug and enhance when Loops and Subroutines have one entry and one exit. Thanks, David A. Green www.dagconsulting.com (480) 813-1725 -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen Sent: Friday, February 27, 2009 9:20 AM To: Ardent Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
I agree completely with David. I make it a habit to have one way in and one way out for my loops and subroutines. It makes it much easier to enhance/debug in the future (which is what most of us spend most of our time doing). I will not say I NEVER break this rule, but it is rare. John Israel -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of David A. Green Sent: Friday, February 27, 2009 1:25 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] DO/WHILE vs IF THEN George, In my opinion you lose the elegance and readability of the LOOP construct when you use EXIT. Code is easier to debug and enhance when Loops and Subroutines have one entry and one exit. Thanks, David A. Green www.dagconsulting.com (480) 813-1725 -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen Sent: Friday, February 27, 2009 9:20 AM To: Ardent Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
See below. Nicholas M Gettino | Director of Development | EnRoute Emergency Systems, an Infor company | office: 813-207-6998 | fax: 678-393-5389 nick.gett...@infor.com | www.enroute911.com First time through... Example: 0001: CTR=0 0002: LOOP First pass thruSecond pass thru 0003: CTR=CTR+1 CTR is 1 adds 1 to CTR making it 8 0004: WHILE CTR4 DO since CTR is NOW more than 4 it stops Read below. 0005: PRINT CTR prints a 1 0006: CTR=CTR+1 adds 1 to CTR 0007: PRINT CTR prints a 2 0008: CTR=CTR+1 adds 1 to CTR 0009: PRINT CTR prints a 3 0010: CTR=CTR+1 adds 1 to CTR 0011: PRINT CTR prints a 4 0012: CTR=CTR+1 adds 1 to CTR 0013: PRINT CTR prints a 5 0014: CTR=CTR+1 adds 1 to CTR 0015: PRINT CTR prints a 6 0016: CTR=CTR+1 adds 1 to CTR 0017: PRINT CTR prints a 7 0018: REPEAT goes back to LOOP 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. [Nick] Should have been written. CTR=0 LOOP WHILE CTR 4 DO CTR = CTR + 1 REPEAT --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
I actually think, from the distant reaches of my memory, that this might behave differently depending on the uv flavor... -Dianne Nick Gettino wrote: See below. Nicholas M Gettino | Director of Development | EnRoute Emergency Systems, an Infor company | office: 813-207-6998 | fax: 678-393-5389 nick.gett...@infor.com | www.enroute911.com First time through... Example: 0001: CTR=0 0002: LOOP First pass thruSecond pass thru 0003: CTR=CTR+1 CTR is 1 adds 1 to CTR making it 8 0004: WHILE CTR4 DO since CTR is NOW more than 4 it stops Read below. 0005: PRINT CTR prints a 1 0006: CTR=CTR+1 adds 1 to CTR 0007: PRINT CTR prints a 2 0008: CTR=CTR+1 adds 1 to CTR 0009: PRINT CTR prints a 3 0010: CTR=CTR+1 adds 1 to CTR 0011: PRINT CTR prints a 4 0012: CTR=CTR+1 adds 1 to CTR 0013: PRINT CTR prints a 5 0014: CTR=CTR+1 adds 1 to CTR 0015: PRINT CTR prints a 6 0016: CTR=CTR+1 adds 1 to CTR 0017: PRINT CTR prints a 7 0018: REPEAT goes back to LOOP 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. [Nick] Should have been written. CTR=0 LOOP WHILE CTR 4 DO CTR = CTR + 1 REPEAT --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
I should offer a contrary opinion. I support many sets of differently developed code with all my clients. When properly indented, the EXIT is a logical way to conclude the visit in the loop without labeling the REPEAT or introducing other DONE 'style' variables. The code actually shrinks by a few lines. Example: Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT Or my favorite code shrinking syntax: before EOF=0 LOOP READNEXT ID ELSE EOF=0 UNTIL EOF DO {process} REPEAT after LOOP WHILE READNEXT ID DO {process} REPEAT When I see code that has been heavily flagged I have to scratch my head. EXIT and CONTINUE have been around at least as long as U2 has. I know that they weren't there during the Jurrasic Pick era. My 1 cent, Mark Johnson Maybe I follow poor programmers who got flag-crazy. - Original Message - From: David A. Green dgr...@dagconsulting.com To: u2-users@listserver.u2ug.org Sent: Friday, February 27, 2009 1:25 PM Subject: RE: [U2] DO/WHILE vs IF THEN George, In my opinion you lose the elegance and readability of the LOOP construct when you use EXIT. Code is easier to debug and enhance when Loops and Subroutines have one entry and one exit. Thanks, David A. Green www.dagconsulting.com (480) 813-1725 -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen Sent: Friday, February 27, 2009 9:20 AM To: Ardent Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
What my test program was to show, is that the WHILE/DO will only end the loop if the condition is not met when execution is on the WHILE/DO line (line 4). In other words, the loop will not be ended when CTR3, but rather when CTR3 AND it is being checked by the WHILE/DO Line. I was testing that the loop would not just end on line 10 during the FIRST pass thru (when the condition became false CTR=4). Since the problem I was having was a loop that was justing ending between two statements, with neither statement being a conditional check, nor contained an EXIT, so the test program was just to prove to myself that WHILE/DO isn't some sort of overlord that monitors for the condition at all points within the loop and will end the loop immediately upon that condition not being met. So, the question still remains...wha happened? any why when I removed the WHILE/DO line did it stop happening? If I can gain any more meaningful information using RAID I will repost otherwise, it's just going to be one of those things But thank you for the responses of things to check into. George -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2- us...@listserver.u2ug.org] On Behalf Of Nick Gettino Sent: Friday, February 27, 2009 2:34 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] DO/WHILE vs IF THEN See below. Nicholas M Gettino | Director of Development | EnRoute Emergency Systems, an Infor company | office: 813-207-6998 | fax: 678-393-5389 nick.gett...@infor.com | www.enroute911.com First time through... Example: 0001: CTR=0 0002: LOOP First pass thruSecond pass thru 0003: CTR=CTR+1 CTR is 1 adds 1 to CTR making it 8 0004: WHILE CTR4 DO since CTR is NOW more than 4 it stops Read below. 0005: PRINT CTR prints a 1 0006: CTR=CTR+1 adds 1 to CTR 0007: PRINT CTR prints a 2 0008: CTR=CTR+1 adds 1 to CTR 0009: PRINT CTR prints a 3 0010: CTR=CTR+1 adds 1 to CTR 0011: PRINT CTR prints a 4 0012: CTR=CTR+1 adds 1 to CTR 0013: PRINT CTR prints a 5 0014: CTR=CTR+1 adds 1 to CTR 0015: PRINT CTR prints a 6 0016: CTR=CTR+1 adds 1 to CTR 0017: PRINT CTR prints a 7 0018: REPEATgoes back to LOOP 0019: STOP 0020: END --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
Re: [U2] DO/WHILE vs IF THEN
I use exit as my single point out by not including a WHILE or UNTIL. SELECT YADAYADA LOOP READNEXT KEY ELSE EXIT Do Stuff Do Stuff REPEAT Israel, John R. wrote: I agree completely with David. I make it a habit to have one way in and one way out for my loops and subroutines. It makes it much easier to enhance/debug in the future (which is what most of us spend most of our time doing). I will not say I NEVER break this rule, but it is rare. John Israel -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of David A. Green Sent: Friday, February 27, 2009 1:25 PM To: u2-users@listserver.u2ug.org Subject: RE: [U2] DO/WHILE vs IF THEN George, In my opinion you lose the elegance and readability of the LOOP construct when you use EXIT. Code is easier to debug and enhance when Loops and Subroutines have one entry and one exit. Thanks, David A. Green www.dagconsulting.com (480) 813-1725 -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen Sent: Friday, February 27, 2009 9:20 AM To: Ardent Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ -- Jeff Schasny - Denver, Co, USA jschasny at gmail dot com /Come To The Dark Side, We Have Cookies./ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/
RE: [U2] DO/WHILE vs IF THEN
In all your examples, you support my position. 1 way in, 1 way out. Though to your point, you have clean, concise clean code. John Israel -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of MAJ Programming Sent: Friday, February 27, 2009 3:23 PM To: u2-users@listserver.u2ug.org Subject: Re: [U2] DO/WHILE vs IF THEN I should offer a contrary opinion. I support many sets of differently developed code with all my clients. When properly indented, the EXIT is a logical way to conclude the visit in the loop without labeling the REPEAT or introducing other DONE 'style' variables. The code actually shrinks by a few lines. Example: Before GOOD.ANS=FALSE LOOP UNTIL GOOD.ANS DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN GOOD.ANS=TRUE REPEAT after LOOP WHILE TRUE DO PRINT ENTER 'Y' OR 'N' :;INPUT ANS IF ANS=Y OR ANS=N THEN EXIT REPEAT Or my favorite code shrinking syntax: before EOF=0 LOOP READNEXT ID ELSE EOF=0 UNTIL EOF DO {process} REPEAT after LOOP WHILE READNEXT ID DO {process} REPEAT When I see code that has been heavily flagged I have to scratch my head. EXIT and CONTINUE have been around at least as long as U2 has. I know that they weren't there during the Jurrasic Pick era. My 1 cent, Mark Johnson Maybe I follow poor programmers who got flag-crazy. - Original Message - From: David A. Green dgr...@dagconsulting.com To: u2-users@listserver.u2ug.org Sent: Friday, February 27, 2009 1:25 PM Subject: RE: [U2] DO/WHILE vs IF THEN George, In my opinion you lose the elegance and readability of the LOOP construct when you use EXIT. Code is easier to debug and enhance when Loops and Subroutines have one entry and one exit. Thanks, David A. Green www.dagconsulting.com (480) 813-1725 -Original Message- From: owner-u2-us...@listserver.u2ug.org [mailto:owner-u2-us...@listserver.u2ug.org] On Behalf Of George Gallen Sent: Friday, February 27, 2009 9:20 AM To: Ardent Subject: [U2] DO/WHILE vs IF THEN OK Aside from programming styles Is there any functional difference between WHILE expression DOand IF NOT(expression) THEN EXIT and UNTIL expression DOand IF expression THEN EXIT First I thought that the DO/WHILE would activate as soon as the condition occurred and drop out of a loop, but that is not the case, the condition has to be active AND control has to be back at the WHILE statement. Example: 0001: CTR=0 0002: LOOP 0003: CTR=CTR+1 0004: WHILE CTR4 DO 0005: PRINT CTR 0006: CTR=CTR+1 0007: PRINT CTR 0008: CTR=CTR+1 0009: PRINT CTR 0010: CTR=CTR+1 0011: PRINT CTR 0012: CTR=CTR+1 0013: PRINT CTR 0014: CTR=CTR+1 0015: PRINT CTR 0016: CTR=CTR+1 0017: PRINT CTR 0018: REPEAT 0019: STOP 0020: END My first thought was that once CTR = 5, the loop would end (at LINE 12) but it didn't until control was passed back to LINE 4, then it ended. --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ --- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/