return

The 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 return statement with an expression. A function returning an int is declared. The return statements in this function are followed by int expressions.

function int getOtherPlayer(int player)
{
   if (player == Constants.Player1) return Constants.Player2;
   else return Constants.Player1;
}
Example 2

This second example illustrates a return statement with an expression. The return statement is shown in a rule task body declared with the select keyword. The returned value is of boolean type.

ruletask ExpandObjects
{
   ordering = dynamic;
   firing = allrules;
   body = select(?rule)
   {
      String ?task = ?rule.getProperties().getString("task","");
      return ?task.equals("ExpandObjects");
   }
};