Page 1 of 1

Reserved word "Exit" ?

Posted: Wed Mar 14, 2007 5:56 am
by Gnafu
What does it do?
What is the difference between exit; and return; ?

Posted: Wed Mar 14, 2007 2:55 pm
by OldnGrey
Okay, correct me if I am wrong, but you should end all functions with a return x; statement.

As far a the program body itself, I have seen exit used to quit the program (eg inside a loop) However I notice that a lot of scripters use return to quit a program body - perhaps they are equivalent.

Posted: Wed Mar 14, 2007 3:14 pm
by Bracco
that's a good question...

i believe that exit just terminates the current script, regardless from where it is called (for example inside a function)
while return just ends the current function (that can also be the main program of course)

also if there isn't a return then the function returns 0 automatically i guess

Posted: Wed Mar 14, 2007 8:50 pm
by Danielle
I believe Bracco is correct.

Calling "exit" will terminate the current script immediately.

And calling "return" will end the current function/program. Return can, as mentioned, be called with or without a variable. When called without a variable, "return", it is the same as calling "return 0".

P.S. Good job on the wiki so far Gnafu!