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

Nested if statements in a while loop

Started by zeus5966, 11 November 2013 - 02:45 AM
zeus5966 #1
Posted 11 November 2013 - 03:45 AM
Title: Nested if statements in a while loop

Hello all, I'm having some troubles with nested if/else statements in a while loop that I've created. Ideally I'd be putting curly brackets and round brackets everywhere, but because of the language I'm slightly stuck. If anyone could shed some light on the matter that would be great.

Here's the code

local roofLength = 0
local lengthCounter = 0
while lengthCounter <= roofLength do
  if not turtle.detect() then
    turtle.placeDown()
    turtle.forward()
  end
  else
    turtle.forward()
  end
end
Bubba #2
Posted 11 November 2013 - 12:43 PM
You put an end before the else statement. You'll want to remove the end just before the else statement and it will work fine.

if [thing] then
  ...
else
  ...
end
zeus5966 #3
Posted 11 November 2013 - 01:04 PM
Okay I see. Thank you