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

How do I loop a program

Started by deatheater99, 15 April 2012 - 04:19 PM
deatheater99 #1
Posted 15 April 2012 - 06:19 PM
What I want to do is loop this program so I don't have to keep retyping it but I can't figure out how.

I want to loop this.


turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()

So it will end up making a staircase to bedrock.
Thanks in advanced
EDIT: figured it out so you can delete this.
1v2 #2
Posted 15 April 2012 - 06:26 PM
You could use

while true do
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end
but this will go on for ever so i recommend using it like this


x = 0
while x < 20 do
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end
This will repeat the code for 20 times.
cant_delete_account #3
Posted 15 April 2012 - 06:27 PM
IGNORE
cant_delete_account #4
Posted 15 April 2012 - 06:28 PM
SpoilerYou could use

while true do
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end
but this will go on for ever so i recommend using it like this


x = 0
while x < 20 do
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end
This will repeat the code for 20 times.
If you want to do it a certain amount of times, don't use that, use a for loop:

local amount = 5 -- Change 5 to how many times you want to loop it
for DoNotChangeThis=1,amount do
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end
Code for doing it forever:

while true do
sleep(0)
turtle.digDown()
turtle.down()
turtle.dig()
turtle.forward()
turtle.dig()
end