in reply to Re^2: Repeat question (redo)
in thread Repeat question
You would put one of the constructs suggested by haukex or LanX inside the while from your original code, around your if/else block.
(Also, rather than having that if/else block, and repeating two almost-identical pieces of code: after generating the two random numbers, I would suggest using this to swap them, so the first is always bigger than the second:
That way, you only need one piece of code for asking and checking the answer, rather than two nearly-identical pieces. There are more perlish ways of doing the swap, but I chose to make it easy for you to understand.)if($random_integer1 < $random_integer2) { my $tmp = $random_integer2; $random_integer2 = $random_integer1; $random_integer1 = $tmp; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Repeat question (redo)
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 |