Loop Node


A Loop Structured Activity Node by default has Setup, Test and Body partitions. The Setup partition is executed once on entry to the Loop, and the Test and Body partitions are executed repeatedly until the Test produces a false value. The results of the final execution of the Test or Body are available after execution of the Loop is complete.

They are depicted on an Activity diagram as shown below:


You define the Loop nodes by dragging other Activity diagram elements from the Toolbox page into the appropriate partition of the element, and linking and organizing the structure as required. The elements are aligned on the top left of the partition, so that resizing the node maintains the organization of the structure within and between the partitions. If you try to shrink the node below the structure size, the node automatically defaults to the 'best fit' size.

When you create a Loop Node, the element Properties dialog displays. Much of this you can complete as for any other element. However, for the Loop Node the dialog also has a Loop tab.

Add an Action Pin for each of the Decider, Loop Variable Input, Loop Variable, Body Output and Result fields for the node, in each case clicking on the Browse or Add button to display the Select Pins dialog (a version of the Select <Item> dialog). The Select ActionPin dialog reveals only Input pins (Loop Variable Input) or Output pins as appropriate to the context. If the required Action Pin does not already exist, you can click on the Add New button on the dialog to automatically create the Input pin or an Output pin under the appropriate parent node.

You can also check on the exact location of an existing Action Pin by right-clicking on the pin name and selecting the Find in Project Browser context menu option.

The Nodes panel, by default, lists the Actions and Activities contained in the Setup partition. Click on the Body or Test radio buttons to list the elements contained in the corresponding partitions. An element must be completely contained in a partition to be listed there - if it overlaps with the partition above in any way, it is treated as being part of that partition.

OMG UML Specification

The OMG UML specification (UML Superstructure Specification, v2.1.1, pp. 384-385) states:

A loop node is a structured activity node that represents a loop with setup, test, and body sections.

Each section is a well-nested subregion of the activity whose nodes follow any predecessors of the loop and precede any successors of the loop. The test section may precede or follow the body section. The setup section is executed once on entry to the loop, and the test and body sections are executed repeatedly until the test produces a false value. The results of the final execution of the test or body are available after completion of execution of the loop.