How to resolve the algorithm Loops/With multiple ranges step by step in the VBA programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/With multiple ranges step by step in the VBA programming language

Table of Contents

Problem Statement

Some languages allow multiple loop ranges, such as the PL/I example (snippet) below.

Simulate/translate the above PL/I program snippet as best as possible in your language,   with particular emphasis on the   do   loop construct. The   do   index must be incremented/decremented in the same order shown. If feasible, add commas to the two output numbers (being displayed). Show all output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/With multiple ranges step by step in the VBA programming language

Source code in the vba programming language

Dim prod As Long, sum As Long
Public Sub LoopsWithMultipleRanges()
    Dim x As Integer, y As Integer, z As Integer, one As Integer, three As Integer, seven As Integer, j As Long
    prod = 1
    sum = 0
    x = 5
    y = -5
    z = -2
    one = 1
    three = 3
    seven = 7
    For j = -three To pow(3, 3) Step three: Call process(j): Next j
    For j = -seven To seven Step x: Call process(j): Next j
    For j = 555 To 550 - y: Call process(j): Next j
    For j = 22 To -28 Step -three: Call process(j): Next j
    For j = 1927 To 1939: Call process(j): Next j
    For j = x To y Step z: Call process(j): Next j
    For j = pow(11, x) To pow(11, x) + one: Call process(j): Next j
    Debug.Print " sum= " & Format(sum, "#,##0")
    Debug.Print "prod= " & Format(prod, "#,##0")
End Sub
Private Function pow(x As Long, y As Integer) As Long
    pow = WorksheetFunction.Power(x, y)
End Function
Private Sub process(x As Long)
    sum = sum + Abs(x)
    If Abs(prod) < pow(2, 27) And x <> 0 Then prod = prod * x
End Sub

  

You may also check:How to resolve the algorithm Elliptic curve arithmetic step by step in the Go programming language
You may also check:How to resolve the algorithm Tau function step by step in the F# programming language
You may also check:How to resolve the algorithm Sylvester's sequence step by step in the PL/M programming language
You may also check:How to resolve the algorithm RSA code step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm File size step by step in the Erlang programming language