Purpose of the return statement
Irvine_audit
What exactly is the purpose of the return statement?
I read about it in the manual and searched for "return statement" and it striked me as being important. However, it is not quite clear to me why you would not just write all results of a function in either waves, variables or strings etc. and use conditional expressions to continue or break loops and so on. So how do I benefit from using "return" in functions and where is it stringently required?
Best regards,
Martin
Consider this example
variable var
return var == 1
End
Now if you do
print IsOne(1)
on the command line you get the result of IsOne. A return statement is the primary way to return information from a function you call.October 22, 2014 at 08:35 am - Permalink
- you want to end a function call somewhere in-between ( e.g. if X -> return)
- returning the function status (e.g., hook functions)
- functions mainly calculating values / constructing strings
- passing things without using a global variable (should be avoided as much as possible)
- error handling
October 24, 2014 at 08:17 am - Permalink
That actually helped me understanding the use of this statement.
October 25, 2014 at 02:49 am - Permalink