The three newlines help to clear out the users input and make a nicer looking response if they fail to answer with a correct letter. Since $answer has already been set, after the loop you can say:do { print "\nDid I guess your animal?\n\n"; } while ($answer=<STDIN>) !~ /^[YN]/i; ## OR do { print "\nDo you want to <P>lay again or <Q>uit?\n\n"; } while ($answer=<STDIN>) !~ /^[PQ]/i;
if ($answer =~ /^P/i) { ## Code for P here } ## Add some elsifs if > 2 choices else { ## No need to check the final letter ## Code for Q here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Do/while correct answer loop
by merlyn (Sage) on May 12, 2000 at 19:49 UTC | |
by turnstep (Parson) on May 12, 2000 at 19:54 UTC |