How to resolve the algorithm Loops/With multiple ranges step by step in the FutureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/With multiple ranges step by step in the FutureBasic 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 FutureBasic programming language
Source code in the futurebasic programming language
window 1, @"Loops with Ranges", ( 0, 0, 400, 400 )
begin globals
NSInteger sum = 0
float prod = 1
end globals
local fn process( x as float )
sum += abs(x)
if abs(prod) < (2 ^ 27) and x <> 0 then prod = prod * x
end fn
NSInteger j
NSInteger x = 5, y = -5, z = -2
NSInteger one = 1, three = 3, seven = 7
for j = -three to (3 ^ 3) step three: fn process(j): next j
for j = -seven to seven step x: fn process(j): next j
for j = 555 to 550 - y: fn process(j): next j
for j = 22 to -28 step -three: fn process(j): next j
for j = 1927 to 1939: fn process(j): next j
for j = x to y step z: fn process(j): next j
for j = (11 ^ x) to (11 ^ x) + one: fn process(j): next j
print using " sum = ###,###"; sum
print using "prod =-####,###,###"; prod
HandleEvents
You may also check:How to resolve the algorithm Greatest common divisor step by step in the EDSAC order code programming language
You may also check:How to resolve the algorithm Euler's sum of powers conjecture step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Nested templated data step by step in the J programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the OCaml programming language
You may also check:How to resolve the algorithm Word wheel step by step in the Python programming language