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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Nested step by step in the Sather 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 Sather programming language

Source code in the sather programming language

class MAIN is
  main is
    a:ARRAY2{INT} := #(10,10);
    i, j :INT;
    
    RND::seed(1230);
    loop i := 0.upto!(9);
      loop j := 0.upto!(9);
         a[i, j] := RND::int(1, 20);
      end;
    end;

    loopthis ::= true;
    loop i := 0.upto!(9); while!( loopthis );
      loop j := 0.upto!(9);
        #OUT  + " " + a[i, j];
        if a[i, j] = 20 then
	  loopthis := false;
	  break!;
	end;
      end;
    end;
  end;
end;

  

You may also check:How to resolve the algorithm Literals/Integer step by step in the Aime programming language
You may also check:How to resolve the algorithm SHA-1 step by step in the Clojure programming language
You may also check:How to resolve the algorithm A+B step by step in the Ra programming language
You may also check:How to resolve the algorithm Entropy step by step in the Raku programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the PicoLisp programming language