WisDomSeeKer34 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/env perl use strict; use warnings; use utf8; use feature 'say'; sub choose { say "choose a number: 1 2 3 4 5 "} choose(); my $x = <STDIN>; say $x; if ($x<1 or $x>5) { say"You have chosen the wrong number"; choose(); $x = <STDIN>; }
If you enter the wrong number, you get the new message again. But only once. I want the message to repeat until you type in the right number.
I am working on this code, because I have still the Basic syntax in mind:
if ($x<1 or $x>5) THEN GOTO 10
and that doesn't work that way in Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for a loop
by Athanasius (Archbishop) on May 28, 2018 at 07:54 UTC | |
by thanos1983 (Parson) on May 28, 2018 at 09:32 UTC | |
|
Re: Looking for a loop
by karlgoethebier (Abbot) on May 28, 2018 at 17:40 UTC | |
|
Re: Looking for a loop
by Marshall (Canon) on May 30, 2018 at 06:30 UTC | |
|
Re: Looking for a loop
by Anonymous Monk on May 28, 2018 at 15:59 UTC | |
by jeffenstein (Hermit) on May 28, 2018 at 16:31 UTC |