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

break doesn't like me?

Started by brett122798, 21 January 2013 - 08:15 AM
brett122798 #1
Posted 21 January 2013 - 09:15 AM
Well here's what's happening.. I have a while true do thingy that contains an if statement and when I add break to the code, it has this error:


bios:338: [string "mdm"]:362: 'end' expected (to close 'if' at line 360)

But I already have an end to close the if! Here's my statement:


while true do
if menucont == "host" then
break
goroutine.kill("Button2")
goroutine.kill("Button3")
host()
elseif menucont == "connect" then
break
goroutine.kill("Button1")
goroutine.kill("Button3")
connect()
elseif menucont == "quit" then
break
goroutine.kill("Button1")
goroutine.kill("Button2")
term.clear()
term.setCursorPos(1, 1)
end
sleep(0.1)
end
theoriginalbit #2
Posted 21 January 2013 - 09:19 AM
Using break will immediately exit the loop and ignore any of the lines in the if statement after it. The compiler may be picking up on this.
Willibilly19 #3
Posted 21 January 2013 - 09:19 AM
It would help if you could post the whole code or add a pastebin link to it. Another alternative is adding indenting to your code (ie: spacing your if statement in a few spaces) and putting the code into notepad++. It highlights the code for you and helps determine what's wrong.


*Edit* sorry if that came off a bit rude or anything, I just didn't see anything wrong with the code so I figured it was somewhere else that had the issue.
brett122798 #4
Posted 21 January 2013 - 09:21 AM
Using break will immediately exit the loop and ignore any of the lines in the if statement after it. The compiler may be picking up on this.
Oh, but still.. why am I getting that error? I've closed that if statement.
sjele #5
Posted 21 January 2013 - 09:22 AM
"For syntax reasons break can only appear at end of a block"

http://www.lua.org/pil/4.4.html
brett122798 #6
Posted 21 January 2013 - 09:25 AM
"For syntax reasons break can only appear at end of a block"

http://www.lua.org/pil/4.4.html
Oh! That makes so much more sense now.. thanks!
theoriginalbit #7
Posted 21 January 2013 - 09:42 AM
putting the code into notepad++. It highlights the code for you and helps determine what's wrong.
The forums code tags don't like it when the code is already colored.
ChunLing #8
Posted 21 January 2013 - 02:17 PM
In the case of notepad++, the coloring has no effect on the text.