called (variable)

This construct provides a name for a variable declared in a for each action statement.

Purpose

You use this construct in the outer loop of nested for each loops so that you can reference the named item from within the inner loop.

Syntax

called <variable>,

Description

When using a for each statement to do an action on a set of items, a variable is created automatically to allow you to refer to each item in turn as ‘this item’ (see the first example below). However, if you nest one for each loop inside another, you must give the variable in the outer loop a name so that you can reference it from within the inner loop (see the second example below).

Example

The following rule shows a simple for each action statement. There is no need to use the called construct in this case.

if
    the category of the customer is Gold
then
    for each customer in ‘senior customers’:
        - send flowers to this customer;

The following rule shows two nested for each statements. The called construct is used so that each customer can be explicitly referred to from within the nested for each loop.

if
   the category of the customer is Gold
then
   for each customer called c, in ‘senior customers’:
      - for each account in ‘new accounts’:
         - send a statement for this account to the mailing address of c;