RosettaCodeData/Task/Loops-With-multiple-ranges/M2000-Interpreter/loops-with-multiple-ranges....

31 lines
792 B
Plaintext

Module MultipleLoop {
long sum=0, x=+5,y=-5, z=-2, j
double prod=1
const one=1&, three=3&, seven=7&
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
}
}
flush
data Range(-three, 3**3, three), Range(-seven, +seven, x), Range(555, 550-y), Range(22, -28, -three)
data Range(1927, 1939), Range(x,y,z), Range(11**x, 11**x+one)
Exec=MultipleRange(![])
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