GREETINGS
is there a way of getting just even only on an iteration?
for example
i want to separate 1,3,5,7,9 from 2,4,6,8,10
from a for do loop??
from i=1, 10 do
do something
end
GREETINGS
is there a way of getting just even only on an iteration?
for example
i want to separate 1,3,5,7,9 from 2,4,6,8,10
from a for do loop??
from i=1, 10 do
do something
end
the third (optional) value in a for loop is the increment value, fe:
for i = 1,9,2 do print(i) end -- 1,3,5,7,9 for i = 1,10,2 do print(i) end -- same as above, 10 is skipped on the way to 11, ending loop at 9 for i = 2,10,2 do print(i) end -- 2,4,6,8,10 for i = 10,2,-2 do print(i) end -- 10,8,6,4,2
or if trying to process both in one loop, but do something different, then modulo:
for i = 1,10 do if (i%2 == 0) then print(i.." is even") else print(i.." is odd") end end
the third (optional) value in a for loop is the increment value, fe:
for i = 1,9,2 do print(i) end -- 1,3,5,7,9 for i = 1,10,2 do print(i) end -- same as above, 10 is skipped on the way to 11, ending loop at 9 for i = 2,10,2 do print(i) end -- 2,4,6,8,10 for i = 10,2,-2 do print(i) end -- 10,8,6,4,2
or if trying to process both in one loop, but do something different, then modulo:
for i = 1,10 do if (i%2 == 0) then print(i.." is even") else print(i.." is odd") end end