Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over 



[
1
,
…
,
20
]


{\displaystyle [1,\ldots ,20]}

.

The loops iterate rows and columns of the array printing the elements until the value 



20


{\displaystyle 20}

 is met.

Specifically, this task also shows how to break out of nested loops.



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
   Loops/Wrong ranges


PROC Main()
  DEFINE PTR="CARD"
  BYTE i,j,found
  PTR ARRAY a(10)
  BYTE ARRAY tmp,
    a0(10),a1(10),a2(10),a3(10),a4(10),
    a5(10),a6(10),a7(10),a8(10),a9(10)
 
  a(0)=a0 a(1)=a1 a(2)=a2 a(3)=a3 a(4)=a4
  a(5)=a5 a(6)=a6 a(7)=a7 a(8)=a8 a(9)=a9
 
  FOR j=0 TO 9
  DO
    tmp=a(j)
    FOR i=0 TO 9
    DO
      tmp(i)=Rand(20)+1
    OD
  OD
 
  found=0
  FOR j=0 TO 9
  DO
    tmp=a(j)
    FOR i=0 TO 9
    DO
      PrintB(tmp(i)) Put(32)
      IF tmp(i)=20 THEN
        found=1 EXIT
      FI
    OD
    IF found THEN
      EXIT
    FI
    PutE()
  OD
RETURN