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

[Question] How would one run a program a specific number of times?

Started by The, 20 May 2012 - 12:24 AM
The #1
Posted 20 May 2012 - 02:24 AM
I wish to have a turtle execute a program a specific number of times. It will dig a tunnel 1000 blocks. Would we call the "function" command or is there some other way to do it? This is the code I have thus far:

turtle.dig()
turtle.forward()
turtle.digUp()
As you can see I have the turtle API section down (the amateur section!). Your help is greatly appreciated.
cant_delete_account #2
Posted 20 May 2012 - 02:28 AM
Use:

print("How many times would you like to run the code? (type it in)")
local amountOfTimes = tonumber(read())
for DoNotChangeThis=1,amountOfTimes do
turtle.dig()
turtle.forward()
turtle.digUp()
end
MathManiac #3
Posted 21 May 2012 - 03:40 PM
Problem: How do you run a program a set amount of times?

Solution:
Use:

print("How many times would you like to run the code? (type it in)")
local amountOfTimes = tonumber(read())
for DoNotChangeThis=1,amountOfTimes do
turtle.dig()
turtle.forward()
turtle.digUp()
end
MysticT #4
Posted 21 May 2012 - 08:08 PM
Problem: How do you run a program a set amount of times?

Solution:
Use:

print("How many times would you like to run the code? (type it in)")
local amountOfTimes = tonumber(read())
for DoNotChangeThis=1,amountOfTimes do
turtle.dig()
turtle.forward()
turtle.digUp()
end
I think it was pretty obious in the other two posts, you don't need to (and you shouldn't) repost someone else's solution.
The #5
Posted 22 May 2012 - 08:55 PM
Thank you for your help.