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

Published on 12 May 2024 09:40 PM

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

Source code in the purebasic programming language

If OpenConsole()

  Repeat
    a = Random(19)
    PrintN(Str(a))
    If a = 10
      Break
    EndIf 
    b = Random(19)
    PrintN(Str(b))
    PrintN("")
  ForEver

  Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
  Input()
  CloseConsole()
EndIf

  

You may also check:How to resolve the algorithm Find limit of recursion step by step in the Python programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm Sierpinski arrowhead curve step by step in the 11l programming language
You may also check:How to resolve the algorithm Euler's sum of powers conjecture step by step in the Forth programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the F# programming language