Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I like to draw a UML sequence diagram to display the sequence of actions and interactions of different parts of my system (I think they called actors).

However, I need to include if then else statements here. Do I do something wrong? Can I use conditional if statements in my UML sequence diagram? How?

share|improve this question

4 Answers 4

up vote 11 down vote accepted

As in many types of UML diagrams, you can use guards to denote a condition. A guard is a boolean expression that you can write over a transition.

Here's a picture with an example: enter image description here

Notice the "[pastDueBalance = 0]" condition.

You can also use combined fragments for more complicated conditional logic. See this nice msdn article for further information.

share|improve this answer
Thanks for the article link! –  quantme Apr 2 '13 at 20:32

There are four possibilities I know of (with increasing power):

  1. The easiest is just using guards, which are simple, side-effect free boolean expressions.
  2. With combined fragments (see e.g. page 54), you can group sets of messages together to show conditional flow in a sequence diagram (alternatives, options, loops)
  3. Much more powerful is the Object Constraint Language (OCL), which can additionally quantify (for all, exists) and offers a full fledged (DesignBy-)Contract language (that is nearly as expressive as full first order logic).
  4. The most powerful way is to express your constraint using a UML Action Language from Executable UML (xUML) that conforms to the UML Action Semantics.

My choice would be the least powerful one that is still sufficiently expressible for what you want to do. For instance, actions in 4. can have side-effects, which makes them much more fragile than OCL.

share|improve this answer

While sequence diagrams are perfect for your description, make sure to check Activity Diagrams.

When you want to show internal details (including detailed rules), Activity Diagrams is what you want to use. The plain activity diagrams focus on sequence of activities and rules and are poor in showing Actor responsibilities, nevertheless, you can use swim lanes to hi-light individual actor's responsibilities. Each lane would include activities an actor is responsible for.

These links discusses activity diagrams with swim lanes:

share|improve this answer

I would say that fragment seems to be the best solution to denote conditions. Found this example on the web: alt text

share|improve this answer
Why do you think fragments are the best solution? –  DaveFar Sep 27 '11 at 8:48
This is the new UML 2 specification but I don't know if this specification is better than the 1.x ? May be not. –  UML_GURU Sep 28 '11 at 9:00
-1 as hotlinking strikes back and the answer is useless ..now –  Tomasz Zielinski May 22 '14 at 17:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.