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:

if($random_integer1 < $random_integer2) { my $tmp = $random_integer2; $random_integer2 = $random_integer1; $random_integer1 = $tmp; }
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.)

Replies are listed 'Best First'.
Re^4: Repeat question (redo)
by Laurent_R (Canon) on Nov 30, 2018 at 18:52 UTC
    This is perfectly OK, but the temporary variable is not really needed and this can be simplified as follows:
    ($random_integer1, $random_integer2) = ($random_integer2, $random_inte +ger1) if $random_integer1 < $random_integer2;

      that was exactly one the "more perlish ways" I was referencing. I would have done it that way for myself, but I thought the explicit swap was more concrete for the OP to understand what was going on.

        Yeah, I guess I missed the last sentence of your previous post when I first read it. I might not have reacted if I had seen it.

        Still, I think it was useful to show this other way of swapping values without using a temporary variable.