RosettaCodeData/Task/Variable-declaration-reset/Pluto/variable-declaration-reset.pluto
2026-04-30 12:34:36 -04:00

19 lines
487 B
Text

local s = {1, 2, 2, 3, 4, 4, 5}
-- There is no output as 'prev' is created anew each time
-- around the loop and set implicitly to nil.
for i = 1, #s do
local curr = s[i]
local prev
if i > 1 and curr == prev then print(i) end
prev = curr
end
-- Now 'prev' is created only once and reassigned
-- each time around the loop producing the desired output.
local prev
for i = 1, #s do
local curr = s[i]
if i > 1 and curr == prev then print(i) end
prev = curr
end