As with the loop constructs, you can break out of a function body block-expression prematurely in MAXScript and return a result without evaluating the remaining portion of the block.
For this purpose, you can use the return expression:
If a return expression is evaluated in the course of running a function body, the function exits immediately and yields the value given in the return <expr> .
If a return <expr> is used in a mapped function and a collection is passed as the first argument to the function, the value returned will be OK rather than <expr> .
As a special case, you can exit a script controller’s script using a return <expr> .
You can call return() in macroScripts whose body is a single expression (old style MacroScripts that do not implement 'on execute do ...' handler) to exit the MacroScript.
WARNING! |
The return expression is very slow. If your function will be called very often, try to avoid using it. See Do not use return, break, exit or continue for details. |