There are a couple of different types of loops to use. while, for, repeat
Example while loops
--infinite while loop
while true do
code here
end
--conditional while loop
while a ~= 1 do
code here
end
Example repeat loop
repeat
code
until a == 1
There are a couple for loops that you can do.
--first repeats a line of code for a set number of times. (simple counter demonstrated)
a = 0
for x=1, 5, 1 do -- x==1 indicates the starting point, the 5 is the number of iterations to run, and 1 is the step so increase by 1 each pass
a = a + 1
print (a)
end
-- the next will use a table and will run the loop for each value in the table example of turning on redstone signals to multiple sides of the comp
local tSides = { "right", "back", "left", "front" }
for var, x in pairs(tSides) do -- var, x sets which var you want to replace with the info from the table, pairs(tSides) selects the table to use
rs.setOutput( x, true)
end
If you run into any problems or need any help let me know.