Purpose of the return statement

Hello everybody,

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

Writing results into global waves, variables, strings should be only done if required.

Consider this example
Function IsOne(var)
    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.
I took a look into some of my procedures, and based on this try to list some uses I can come up with. I think if your function is only for the purpose of modifying data or fiddling with user controls you may not necessarily need a return statement. But there are cases where this get's useful:
- 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