Jump to content




break doesn't like me?


  • You cannot reply to this topic
7 replies to this topic

#1 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

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


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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.

#3 Willibilly19

  • Members
  • 48 posts
  • LocationColorado, USA

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.

#4 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 21 January 2013 - 09:21 AM

 TheOriginalBIT, on 21 January 2013 - 09:19 AM, said:

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.

#5 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

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

#6 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 21 January 2013 - 09:25 AM

 sjele, on 21 January 2013 - 09:22 AM, said:

"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!

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 January 2013 - 09:42 AM

 Willibilly19, on 21 January 2013 - 09:19 AM, said:

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.

#8 ChunLing

  • Members
  • 2,027 posts

Posted 21 January 2013 - 02:17 PM

In the case of notepad++, the coloring has no effect on the text.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users