RosettaCodeData/Task/Loops-With-multiple-ranges/M2000-Interpreter/loops-with-multiple-ranges.m2000
2023-07-01 13:44:08 -04:00

26 lines
760 B
Text

Module MultipleLoop {
def long prod=1, sum=0, x=+5,y=-5, z=-2, one=1, three=3, seven=7, j
Range=lambda (a, b, c=1) ->{
=lambda a, b, c (&f)-> {
if compare(a,b)=sgn(c) then =false else =true: f=a: a+=c
}
}
MultipleRange=Lambda -> {
a=array([]) ' convert stack items in current stack [] to an array of items
=lambda a, k=0 (&f) ->{
do : if k<len(a) Else exit
if a#eval(k, &f) then =true: exit
k++ : always
}
}
Exec=MultipleRange(Range(-three, 3**3, three), Range(-seven, +seven, x), Range(555, 550-y), Range(22, -28, -three), Range(1927, 1939), Range(x,y,z), Range(11**x, 11**x+one))
j=0
while Exec(&j)
sum+=abs(j)
if abs(prod) < 2^27 And j <> 0 then prod*=j
End While
Print "sum=";sum
Print "prod=";prod
}
MultipleLoop