This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
saltstangen's profile picture

Help with running code only every other iteration

Started by saltstangen, 04 July 2013 - 05:07 PM
saltstangen #1
Posted 04 July 2013 - 07:07 PM
I have just started programming in lua (Computercraft) but have a problem:

I have a for loop where there is a bit of code i only want to run ever other time it runs through the loop. How can i do that?
Lyqyd #2
Posted 05 July 2013 - 07:56 PM
Split into new topic.

The usual manner of doing this is to include a conditional block inside your loop that looks a bit like:


if i % 2 == 0 then
 --do things on even numbered iterations
end