UML Activity Diagram Loop

The loop in the activity or algorithm can be depicted in various ways using a UML Activity Diagram.

Loop Node

You can model the loop using the UML Loop Node. The Loop node consists of 3 partitions (activity regions) that contain various parts of the loop:

  • setup - defines the initial conditions of the loop
  • test - defines the condition when the loop can continue. The output value of the activity defined in this partition must be true to continue. If it is false, the flow continues with the next node after the Loop node.
  • body - defines the activity that will be executed when the test condition is fulfilled.
Loop in UML Activity Diagram
Loop in UML Activity Diagram

The example diagram shows a simple loop that iterates from 1 to 10 and repeats an action called 'Do action'.

Simple Flow and Decision Node

The loop can also be depicted using a simple flow with actions and a decision node.

Loop in UML Activity Diagram (Alternative Version)
Loop in UML Activity Diagram (Alternative Version)

Comments

Comdia Pintrest 19 November 2024 14:33:14

Small error - missing merge

if two control flows enter an action it implies there are two tokens runnning. To have the alternative version right in terms of UML activity there is need for a merge before it enters the action "Iterator ++".

Dusan Rodina - softwareideas.net 19 November 2024 14:44:04

RE: Small error - missing merge

Yes, you're right. We apologize for the mistake.

New Comment

Comment