Wiki

Changes between Initial Version and Version 1 of Return

Show
Ignore:
Timestamp:
03/23/10 11:07:35 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Return

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