/* Loops with multiple ranges (Rosetta code) in Picat http://rosettacode.org/wiki/Loops/With_multiple_ranges """ .... prod= 1; sum= 0; x= +5; y= -5; z= -2; one= 1; three= 3; seven= 7; do j= -three to 3**3 by three , -seven to +seven by x , 555 to 550 - y , 22 to -28 by -three , 1927 to 1939 , x to y by z , 11**x to 11**x + one; sum= sum + abs(j); if abs(prod)<2**27 & j¬=0 then prod=prod*j; end; display (' sum= ' || sum); display ('prod= ' || prod); ... """ */ main => go. % Picat has support for multiple ranges but must be stated with different index variables % foreach(I in 1..3, J in 4..6, K in 7..9) % % ... % end go => Prod= 1, Sum= 0, X= +5, Y= -5, Z= -2, One= 1, Three= 3, Seven= 7, Ranges = [-Three..Three..3**3, -Seven..X.. +Seven, 555..550-Y, 22..-Three..-28, 1927..1939, X..Z..Y, 11**X..11**X + One ], foreach(Range in Ranges, J in Range) Sum := Sum + abs(J), if abs(Prod) < 2**27, J != 0 then Prod := Prod * J end end, println(sum=Sum), println(prod=Prod), nl. % A variant is to concatenate all the ranges and flatten to a single list. go2 => Prod= 1, Sum= 0, X= +5, Y= -5, Z= -2, One= 1, Three= 3, Seven= 7, foreach(J in [-Three..Three..3**3, -Seven..X.. +Seven, 555..550-Y, 22..-Three..-28, 1927..1939, X..Z..Y, 11**X..11**X + One ].flatten ) Sum := Sum + abs(J), if abs(Prod) < 2**27, J != 0 then Prod := Prod * J end end, println(sum=Sum), println(prod=Prod), nl.