Task

Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive).

If a number is 10, stop the loop after printing it, and do not generate any further numbers.

Otherwise, generate and print a second random number before restarting the loop.

If the number 10 is never generated as the first number in a loop, loop forever.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges


/*REXX program demonstrates a    FOREVER   DO  loop  with a test to    LEAVE   (break). */
                                                 /*REXX's RANDOM BIF returns an integer.*/
    do forever                                   /*perform loop until da cows come home.*/
    a=random(19)                                 /*same as:    random(0, 19)            */
    call charout , right(a, 5)                   /*show   A   right─justified, column 1.*/
    if a==10  then leave                         /*is random #=10?  Then cows came home.*/
    b=random(19)                                 /*same as:    random(0, 19)            */
    say right(b, 5)                              /*show   B   right─justified, column 2.*/
    end   /*forever*/                            /* [↑]  CHAROUT , xxx   writes to term.*/
                                                 /*stick a fork in it,  we're all done. */