return

action

Syntax
return (expression)?
    


Purpose

To return a value from a function, use the return keyword followed by an expression of the same type as the function return type. For a shelf-class function, the expression must evaluate to a shelf-reference. Executing the return exits the function, so code after the return action will not be executed.

If the function contains an always clause in a scope enclosing the return action, the code in the always clause will be executed after the return action is executed and before the function terminates. The return value of the function is determined when return is executed, and cannot be changed in the always clause. (You can place the return action in the always clause, in which case return will exit the function when it is executed, and the rest of the code in the always clause will not be executed.)

In the following code, return is used to return the result of the function:

  define integer function 
     sum (value integer x,
          value integer y) 
  as
     return x + y

You can also use return by itself to exit from an action function, string source function, or string sink function. If you do not exit an action function, string source function, or string sink function with return, it will exit automatically once all the code is executed. However, a value-returning function, must return a value, and a shelf-class function must return a shelf reference.