| Reference > Rule Languages > Business Action Language > BAL Constructs > for each <object> in <list> |
for each <object> in <list> |
PREVIOUS NEXT |
Specifies that a group of actions must be performed for every element of a collection.
for each <object> [called <variable>,] in <list>:
- <action>;*
This construct enables you to apply one or more actions to all objects in a collection.
The construct should be immediately followed by a colon (:) and a list of one or more actions, each on a separate line, each preceded by a dash. End each action statement with a semi-colon (;).
The implicit variable `this <object>' can be used in each action statement within the for each loop to refer to the current object. If you nest a for each statement inside another, you can use the called construct to define an explicit name for the object in the 'outer' for each loop in order to reference it clearly from within the nested for each loop.
The following rule shows how to apply a discount to all the expensive items in a customer's shopping cart, if the customer is a Gold customer.
definitions
set `smith' to a customer ;
set `expensive items' to all items
in the items of the shopping cart of smith
where the price of `each item' is greater than 1000;
if
the category of smith is Gold
then
for each item in `expensive items':
- apply 5% discount to this item;
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |