Synopsis: return [ return_value ];
The return statement immediately leaves the current function or a current top level block (that contains it) and optionally assigns a return_value to this block. If blocks are nested, i.e. if the current block is contained in another block, the return statement leaves all nested blocks and defines the value of the outermost block.
However, if a block is used in an expression other than a block, and that expression is contained in an outer block, the return statement of the inner block won't leave the outer block but define the value of the inner block. This behavior is a as one would expect. For example in the iteration builtins in Section 8.16, “Applying Expressions To Lists And Maps”,
Example 8.16. return statement 1
{ // This block evaluates to 42. return 42; y2milestone("This command will never be executed"); }
Example 8.18. return statement 3
{ // This program evaluates to 3: integer a = 1 + { return 2; }; return a; }