in reply to Repeat question
(as a variation of Haukex' answer, which is more straight forward )
>perl my $answer = 42; { print "What is the answer? "; chomp( my $input = <STDIN> ); if ( $input == $answer ) { print "Good!\n"; } else { print "Please try again.\n"; redo; } } __END__ What is the answer? 1 Please try again. What is the answer? 2 Please try again. What is the answer? 42 Good!
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Repeat question (redo)
by hchana (Acolyte) on Nov 30, 2018 at 13:56 UTC | |
by pryrt (Abbot) on Nov 30, 2018 at 14:08 UTC | |
by Laurent_R (Canon) on Nov 30, 2018 at 18:52 UTC | |
by pryrt (Abbot) on Nov 30, 2018 at 19:00 UTC | |
by Laurent_R (Canon) on Nov 30, 2018 at 22:24 UTC | |
by hippo (Archbishop) on Nov 30, 2018 at 14:08 UTC | |
by hchana (Acolyte) on Nov 30, 2018 at 14:28 UTC | |
by hippo (Archbishop) on Nov 30, 2018 at 15:18 UTC | |
by hchana (Acolyte) on Nov 30, 2018 at 15:38 UTC | |
by hchana (Acolyte) on Dec 11, 2018 at 11:27 UTC | |
|