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

My loop won't break

Started by Babz, 18 June 2013 - 06:51 PM
Babz #1
Posted 18 June 2013 - 08:51 PM
Hello, I am trying to get my loop to break before line 12. Lets say the user inputs 7 as w. I want lines 4-7 to be executed 7 times while lines 12-14 are only executed 6 times. However even with the break in the loop lines 12-14 are still being executed 7 times.
  • local izard = 0
  • function length()
  • for loop = 1, w do– w is a number that the user inputs.
  • Dig.drill(l-1)– another function in my quarry program.
  • for j = 2, l do
  • turtle.back()
  • end
  • izard=izard+1
  • if izard == w then
  • break
  • else
  • turtle.turnRight()
  • turtle.forward()
  • turtle.turnLeft()
  • end
  • end
  • end
Lyqyd #2
Posted 19 June 2013 - 10:57 AM
Split into new topic.

Initialize `izard` to 1 instead of 0. You also don't need the break, simply have it only execute those lines as long as izard < w.
TheOddByte #3
Posted 21 June 2013 - 12:21 PM
Try to do as Lyqyd said and also… Please use code tags when displaying a code… This was kinda annoying to read…