How to resolve the algorithm Loops/Break step by step in the Oberon-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/Break step by step in the Oberon-2 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 Oberon-2 programming language
Source code in the oberon-2 programming language
MODULE LoopBreak;
IMPORT
RandomNumbers,
Out;
PROCEDURE Do();
VAR
rn: LONGINT;
BEGIN
LOOP
rn := RandomNumbers.RND(20);
Out.LongInt(rn,0);Out.Ln;
IF rn = 10 THEN EXIT END;
rn := RandomNumbers.RND(20);
Out.LongInt(rn,0);Out.Ln
END
END Do;
BEGIN
Do
END LoopBreak.
You may also check:How to resolve the algorithm Hello world/Text step by step in the BML programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Ramanujan primes/twins step by step in the Raku programming language
You may also check:How to resolve the algorithm Window creation step by step in the F# programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Tcl programming language