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

How To Make Code Repeat

Started by dcleondc, 27 February 2012 - 03:02 AM
dcleondc #1
Posted 27 February 2012 - 04:02 AM
hi i want to know how to make code go in a loop. i want to make a tree farm that will grow the tree and harvest it, but i have to restart the program every time i want to harvest a tree, is there a way to make it so when i launch the program it will ask me how many trees i want to harvest for example, lets say i right click the computer and the program starts up and says "How many trees would you like to harvest?" then i enter 8, so then it would loop through the code 8 times to harvest 8 trees.
Kingdaro #2
Posted 27 February 2012 - 04:08 AM

input = read()
num = tonumber(input)

if num then
 for i=1, num do
  --whatever code harvests trees
 end
end