How to resolve the algorithm Loops/Break step by step in the Nemerle programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/Break step by step in the Nemerle 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 Nemerle programming language
Source code in the nemerle programming language
using System;
using System.Console;
using Nemerle.Imperative;
module Break
{
Main() : void
{
def rnd = Random();
while (true)
{
def a = rnd.Next(20);
WriteLine(a);
when (a == 10) break;
def b = rnd.Next(20);
WriteLine(b);
}
}
}
You may also check:How to resolve the algorithm Command-line arguments step by step in the Prolog programming language
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the zkl programming language
You may also check:How to resolve the algorithm Floyd's triangle step by step in the Python programming language
You may also check:How to resolve the algorithm Sort disjoint sublist step by step in the Scheme programming language
You may also check:How to resolve the algorithm CSV to HTML translation step by step in the Lambdatalk programming language