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

Published on 12 May 2024 09:40 PM

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

Source code in the aime programming language

integer
main(void)
{
    integer a, b;

    while (1) {
        a = drand(19);
        o_integer(a);
        o_byte('\n');
        if (a == 10) {
            break;
        }

        b = drand(19);
        o_integer(b);
        o_byte('\n');
    }

    return 0;
}

  

You may also check:How to resolve the algorithm Remove duplicate elements step by step in the Pop11 programming language
You may also check:How to resolve the algorithm Factorial primes step by step in the Ring programming language
You may also check:How to resolve the algorithm Window management step by step in the Ring programming language
You may also check:How to resolve the algorithm Record sound step by step in the OCaml programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Logo programming language