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/

Reply via email to