How to resolve the algorithm Loops/Nested step by step in the SPL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Nested step by step in the SPL programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/Nested step by step in the SPL programming language

Source code in the spl programming language

'fill array
mx,my = 30
> y, 1..my
  > x, 1..mx
    a[x,y] = #.rnd(20)+1
  <
<
'scan array
> y, 1..my
  > x, 1..mx
    #.output("x=",x,", y=",y, ", a=",a[x,y])
    << a[x,y] = 20
  <
  << x!>mx
<

  

You may also check:How to resolve the algorithm Cullen and Woodall numbers step by step in the Quackery programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Erlang programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Hash join step by step in the Prolog programming language