for each (object) called (variable), in (list)

This construct specifies that the rest of the rule must be applied to each element of a collection.

Purpose

You use this construct at the very beginning of the rule, and before the definitions part, to apply the rest of the rule to every object in a collection.

This construct is the equivalent of the construct set <variable> to <definition> in <list> that can be used in the definitions part of the rule.

Syntax

for each <object> [called <variable>], in <list>

Description

When using a for each statement to perform an action on a set of items, a variable is created automatically to represent each item in the collection. You use the called <variable> construct to refer to this variable with a custom name. This custom name can also be used to specifically refer to this variable in a nested for each construct.

Note: The called <variable> part is mandatory in the preconditions of decision tables.

Example

The following rule shows how to add heats to a list of matching heats by looking at each heat, checking whether it meets the conditions, and if so, adding it to the decision.

for each heat called heat, in heats
if
   the area of swimmer is the area of heat
   and the category of heat is 'swimmer heat'
then
   add "Here is a heat that we recommend for you: " + the name of heat to decision;