Actions with parameters
An action can take an optional list of parameters.
Formal parameters
The formal parameters are a comma-separated list of type name and identifier pairs.
The identifier is the name of a parameter variable that will be bound to a copy of the value of an expression specified by the caller (that is, the value passed by the caller) when the action is invoked. The number and type of actual parameters passed by a caller must match those listed in the action’s formal parameters.
The scope of a parameter variable is the statement or block that forms the action body. Parameter variables are very similar to an action’s local variables.
Action return value
If you specify a
returns clause, then the action must return a value whose type matches that specified in the
returns clause. You specify the return value by using a
return statement and result expression within the action. Every control path (see
Transfer of control statements) within the action body must lead to a
return statement with a result expression of the correct type.
Action body
After the returns clause (or after the formal parameters if there is no returns clause), a statement forms the action body. The action body can be a single statement or a block.
Within the action body, you use the parameter variable names to obtain the values that are passed to the action by its caller.