56

I'd like to represent a loop in a UML activity diagram. Here's my situation:

  • For each folder, I check each document within that folder
  • For each document I check its content:
    • If it's invalid (based on keyword searching), do action X and pass to next document.
  • When all document are verified, continue to the next folder.

Can anyone show me what this should look like?

Jim Fell
  • 13,750
  • 36
  • 127
  • 202
hereForLearing
  • 1,209
  • 1
  • 15
  • 33

1 Answers1

79

There are 3 different notations that you can use.

As your loop is based on some elements (folders, documents) the most convenient way is to use Expansion Region (of iterative type). Expansion Region example

Second option, that is a preferred choice when you have some guard based loop is a Loop Node. Loop Node example

The last possibility is to simply build correctly structured decision/merge structure. Decision/Merge example

The benefits of the first two are that they are compact and clear. It is also easy to have nested loops. Neither of this is true with the last option. Yet if you present your diagram to someone who is not familiar with UML (especially if you have no chance to explain a meaning of particular structure), the last approach usually is most widely recognized and understood.

Ister
  • 5,958
  • 17
  • 26
  • Thank you for your answer, I couldn't find any of the these two loops in StarUML, can you please give me a software/online tool that allow to create activity diagram like that? – hereForLearing Jun 08 '16 at 19:19
  • Well, I'm using Enterprise Architect but that's a proprietary tool. I have no idea if any of the free tools has this nodes. – Ister Jun 08 '16 at 19:47
  • Example diagrams reflecting your case added for more clarity. – Ister Jun 08 '16 at 20:28
  • btw I found "condition node" in "Modelio 3.5" it's a free software – hereForLearing Jun 08 '16 at 20:29
  • Thank you for the examples! – hereForLearing Jun 08 '16 at 20:29
  • Close, but conditional node is used to replace if-then-else structure, not loop. However this is also a structured activity. Check, maybe it is possible to change the type of node somehow. – Ister Jun 08 '16 at 20:44
  • I wanted to say "loop node" sorry :/, concerning your answer I couldn't understand many things in your second diagram, like the "yes" and "no" in the final node and can you please explain the "test" and the "body" I couldn't understand them :/ – hereForLearing Jun 08 '16 at 20:45
  • 1
    For the first diagram to be valid, you must use object flows, and those objects have to be manifested somehow. For example, pass in folders from parameter nodes, then later `Extract Files from Folder`. – Jim L. Jun 09 '16 at 00:37
  • 3
    For second diagram - Setup region is run once, when flow enters the node. Test region is run at each iteration after body run and if it returns false, the loop node is exited while if it returns true then the body region is run. There is no clear rule if after setup system shoud run first test or body. Also I've seen diagrams where the test part was just a boolean expression. Specification does not specify an exact method neither provide examples, at least in a relevant part of specification. – Ister Jun 09 '16 at 10:29
  • Just for reference: The Papyrus Modeling environment (https://www.eclipse.org/papyrus/) is an open source tool that supports drawing and even executing Activities with loop nodes. – hielsnoppe Oct 25 '18 at 07:28