Jump to content




exit a program?


12 replies to this topic

#1 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 03:04 AM

How do you exit a program?

#2 CCJJSax

  • Members
  • 262 posts

Posted 12 August 2014 - 03:06 AM

My favorite way is to use
error()


#3 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 03:11 AM

View PostCCJJSax, on 12 August 2014 - 03:06 AM, said:

My favorite way is to use
error()
I know
error()
but... that's like an error. I know
shell.exit()
but I have a while loop.
EDIT: o got it working, I just disabled the while loop. no need to use shell.exit() and/or error()

Edited by !!!!!!!!!!ExclaimationMark, 12 August 2014 - 03:13 AM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 August 2014 - 03:14 AM

This may be a little late, but you can use break to exit a loop, or return to exit a function.

#5 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 03:23 AM

View PostKingofGamesYami, on 12 August 2014 - 03:14 AM, said:

This may be a little late, but you can use break to exit a loop, or return to exit a function.
I know it, but I am outside a loop, so I am using another variable.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 12 August 2014 - 03:48 AM

programs are run in Lua as functions, meaning that if you design your program correctly you can return out of it. if you don't, or its just too difficult to do so, use error, using error with no arguments will exit your program with no output to the user. do not use shell.exit, this does exactly what it says, it exists the shell program, which yes inherently exits your program, but is not a good way to do it!

#7 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 04:30 AM

View Posttheoriginalbit, on 12 August 2014 - 03:48 AM, said:

programs are run in Lua as functions, meaning that if you design your program correctly you can return out of it. if you don't, or its just too difficult to do so, use error, using error with no arguments will exit your program with no output to the user. do not use shell.exit, this does exactly what it says, it exists the shell program, which yes inherently exits your program, but is not a good way to do it!
so...
function exit()
-- exit thing
end
function loop()
while true do
  -- do looping stuff
end
end
loop()
What should be in exit()? error()?

Edited by !!!!!!!!!!ExclaimationMark, 12 August 2014 - 04:31 AM.


#8 natedogith1

  • Members
  • 110 posts

Posted 12 August 2014 - 04:35 AM

You'd instead have something along the lines of
local continue=true
function exit()
continue=false-- exit thing
end
function loop()
while continue do
  -- do looping stuff
end
end
loop()
and, unless you're accessing 'exit' outside of your program, I'd recommend using local functions

#9 flaghacker

  • Members
  • 655 posts

Posted 12 August 2014 - 06:47 AM

Or using break:
while true do --main loop
  --stuff
  break --to exit, use the "break" keyword.  it can be in an if statement
end

Edited by flaghacker, 12 August 2014 - 06:48 AM.


#10 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 06:51 AM

View Postflaghacker, on 12 August 2014 - 06:47 AM, said:

Or using break:
while true do --main loop
  --stuff
  break --to exit, use the "break" keyword.  it can be in an if statement
end
I told you I need to exit the loop outside the loop

#11 flaghacker

  • Members
  • 655 posts

Posted 12 August 2014 - 06:55 AM

View Post!!!!!!!!!!ExclaimationMark, on 12 August 2014 - 06:51 AM, said:

View Postflaghacker, on 12 August 2014 - 06:47 AM, said:

Or using break:
while true do --main loop
  --stuff
  break --to exit, use the "break" keyword.  it can be in an if statement
end
I told you I need to exit the loop outside the loop

Eh, what? You can't stop your program from somewhere else in itself, code that isn't executed simply doesn't do anything.

Or am I misunderstanding what you mean?

#12 !!!!!!!!!!ExclaimationMark

  • Members
  • 30 posts

Posted 12 August 2014 - 07:33 AM

View Postflaghacker, on 12 August 2014 - 06:55 AM, said:

View Post!!!!!!!!!!ExclaimationMark, on 12 August 2014 - 06:51 AM, said:

View Postflaghacker, on 12 August 2014 - 06:47 AM, said:

Or using break:
while true do --main loop
  --stuff
  break --to exit, use the "break" keyword.  it can be in an if statement
end
I told you I need to exit the loop outside the loop

Eh, what? You can't stop your program from somewhere else in itself, code that isn't executed simply doesn't do anything.

Or am I misunderstanding what you mean?

I mean:
function fn1()
 print("doSomething")
end


function fn2()
 fn1()
 fn3()
end


function fn3()
 -- Exit
end
function loop()
-- the main program
end
loop()



#13 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 12 August 2014 - 10:37 AM

If you "must" use that structure, then yeah, it's likely easiest for you to stick error() into fn3.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users