| 1 | = Return Statement = |
| 2 | |
| 3 | The '''return''' statement terminates execution of the method in which it appears and returns control to the calling method. |
| 4 | |
| 5 | The value of the expression clause is returned to the calling function converted to the type specified in the method declaration.[[BR]] |
| 6 | Constructors and destructors, and functions of type void, cannot specify an expression in the return statement.[[BR]] |
| 7 | Functions of all other types must specify an expression in the return statement |
| 8 | |
| 9 | If the return statement is inside a try block, the finally block, if one exists, will be executed before control returns to the calling method. |
| 10 | |
| 11 | == Grammar == |
| 12 | {{{ |
| 13 | return [EXPRESSION] |
| 14 | }}} |
| 15 | |
| 16 | == Example == |
| 17 | {{{ |
| 18 | #Use an expression with a return statement to obtain the largest of two integers. |
| 19 | def max(a as int, b as int) as int is shared |
| 20 | return if(a > b, a, b) |
| 21 | |
| 22 | def main is shared |
| 23 | nOne = 5 |
| 24 | nTwo = 7 |
| 25 | |
| 26 | print String.format( '{0} is bigger', .max( nOne, nTwo ) ) |
| 27 | }}} |