How to resolve the algorithm Loops/With multiple ranges step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/With multiple ranges step by step in the REXX 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 REXX programming language
Source code in the rexx programming language
/*REXX program emulates a multiple─range DO loop (all variables can be any numbers). */
prod= 1;
sum= 0;
x= +5;
y= -5;
z= -2;
one= 1;
three= 3;
seven= 7;
do j= -three to 3**3 by three ; call meat; end;
do j= -seven to seven by x ; call meat; end;
do j= 555 to 550 - y ; call meat; end;
do j= 22 to -28 by -three ; call meat; end;
do j= 1927 to 1939 ; call meat; end;
do j= x to y by z ; call meat; end;
do j= 11**x to 11**x + one ; call meat; end;
say ' sum= ' || commas( sum); /*display SUM with commas. */
say 'prod= ' || commas(prod); /* " PROD " " */
exit; /*stick a fork in it, we're done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: procedure; parse arg _; n= _'.9'; #= 123456789; b= verify(n, #, "M")
e= verify(n, #'0', , verify(n, #"0.", 'M') ) - 4
do j=e to b by -3; _= insert(',', _, j); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
meat: sum= sum + abs(j);
if abs(prod)<2**27 & j\==0 then prod= prod * j;
return;
You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the BASIC256 programming language
You may also check:How to resolve the algorithm Show ASCII table step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Racket programming language
You may also check:How to resolve the algorithm Vector products step by step in the Clojure programming language