RosettaCodeData/Task/Loops-With-multiple-ranges/Pluto/loops-with-multiple-ranges....

61 lines
761 B
Plaintext

local prod = 1
local sum = 0
local x = 5
local y = -5
local z = -2
local one = 1
local three = 3
local seven = 7
local p = math.round(11 ^ x)
local j = 0
local function process()
sum += math.abs(j)
if math.abs(prod) < (1 << 27) and j != 0 then prod *= j end
end
j = -three
while j <= 3 ^ 3 do
process()
j += three
end
j = -seven
while j <= seven do
process()
j += x
end
j = 555
while j <= 550 - y do
process()
++j
end
j = 22
while j >= -28 do
process()
j -= three
end
j = 1927
while j <= 1939 do
process()
++j
end
j = x
while j >= y do
process()
j -= -z
end
j = p
while j <= p + one do
process()
++j
end
print($"sum = {string.formatint(sum)}")
print($"prod = {string.formatint(prod)}")