How to resolve the algorithm Loops/Break step by step in the MOO programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Break step by step in the MOO programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/Break step by step in the MOO programming language

Source code in the moo programming language

while (1)
  a = random(20) - 1;
  player:tell(a);
  if (a == 10)
    break;
  endif
  b = random(20) - 1;
  player:tell(b);
endwhile


  

You may also check:How to resolve the algorithm Product of min and max prime factors step by step in the RPL programming language
You may also check:How to resolve the algorithm Averages/Mode step by step in the SQL programming language
You may also check:How to resolve the algorithm Total circles area step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Set step by step in the Ol programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the bc programming language