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

Published on 12 May 2024 09:40 PM

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

Source code in the vba programming language

Public Sub LoopsBreak()
    Dim value As Integer
    Randomize
    Do While True
        value = Int(20 * Rnd)
        Debug.Print value
        If value = 10 Then Exit Do
        Debug.Print Int(20 * Rnd)
    Loop
End Sub

  

You may also check:How to resolve the algorithm Binary search step by step in the Axe programming language
You may also check:How to resolve the algorithm Factorial step by step in the Red programming language
You may also check:How to resolve the algorithm Prime decomposition step by step in the Picat programming language
You may also check:How to resolve the algorithm Soloway's recurring rainfall step by step in the Nim programming language
You may also check:How to resolve the algorithm Long year step by step in the APL programming language