# Creating a Loop in a Reaction

This task explains how to create a loop in a reaction. In the scenario described below, you are going to:
• Create 3 points that are inserted into a list
• Create a formula that will automatically fill in the list
• Create a reaction that will set the Z coordinate of the points to 20mm if this value is inferior to 20mm.
• Create a reaction that will set the Y coordinate of the points to 40mm if this value is inferior to 40mm.
• Update the Part
It is now possible to create the While and the For constructs. To know more, see the Knowledgeware Language topic.
1. Create a Part containing 3 points.

2. From the Start > Knowledgeware menu, access the Knowledge Advisor workbench.

3. Click the List icon () to create the list that will contain the created points.

4.  Add a formula to fill in the list.

 Click the Formula Editor icon. The Formula Editor is displayed. In the specification tree, select List.1 and click Add formula. List.1=PartBody.Query("Point",""). Click OK twice when done. Note that Japanese users must type the following formula.
1. Click the Reaction icon (). The Reaction dialog box opens.

• In the Source type field, select Selection and select the list in the specification tree for the Reaction to be applied when the list is modified.
• In the Select a source... dialog box, select List.1 and click OK.
• In the Available events list, select ValueChange.
• In the Action field, select Knowledgeware action and enter the following message action body.
 ```let x(Point) for x inside parameter { if (x.GetAttributeReal("Z") < 0.02) x.SetAttributeReal("Z",0.02) }```
• Click OK when done. The Reaction feature is added to the Relations node.
1. Click the Reaction icon (). The Reaction dialog box opens.

• In the Source type field, select Selection and select the list in the specification tree for the Reaction to be applied when the list is modified.
• In the Select a source... dialog box, select List.1 and click OK.
• In the Available events list, select ValueChange.
In the Action field, select Knowledgeware action and enter the following message action body.
 ```let i = 1 let x(Point) for i while i<=parameter.Size() { x = parameter.GetItem(i) if (x.GetAttributeReal("Y") < 0.04) x.SetAttributeReal("Y",0.04) }```
• Click OK when done. The Reaction feature is added to the Relations node.
1. Create a point with the following coordinates:

 X: 36mm Y: 12mm Z: 0mm
2. Update the Part twice: The Y and Z coordinates are set to 40 and 20 mm. Click here to display the result sample.