return
return keyword returns to the caller.
Purpose
The return statement
returns to the caller of the code that contains this statement.
Context
Only in IRL functions or inline IRL code in a task definition, such as initial actions, final actions, the action task body, an agenda filter, or a rule task body defined with the select or dynamicselect keyword.
Syntax
return [expression];
Description
A return statement
with no expression is allowed in a function with the return type void.
In the task definition, such a statement is authorized in initial
actions, final actions, and the action task body.
A return statement
with an expression is allowed in a function with any return type other
than void. The type of the returned expression must
be assignable to the function return type.
A return statement
is not allowed in a rule on either side. It causes a parsing error.
Example
- Example 1
This example illustrates a
returnstatement with an expression. A function returning anintis declared. Thereturnstatements in this function are followed byintexpressions.function int getOtherPlayer(int player) { if (player == Constants.Player1) return Constants.Player2; else return Constants.Player1; }- Example 2
This second example illustrates a
returnstatement with an expression. Thereturnstatement is shown in a rule task body declared with theselectkeyword. The returned value is ofbooleantype.ruletask ExpandObjects { ordering = dynamic; firing = allrules; body = select(?rule) { String ?task = ?rule.getProperties().getString("task",""); return ?task.equals("ExpandObjects"); } };