Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a UML diagram with nested if statements?

Tags:

uml

For example, I have a code like this:

if (morning) {
    if (beforeTenAM) {
        System.out.println("Go back to sleep"); }
    else { 
        System.out.println("Wake up!"); }
}
else {
    System.out.println("It's not morning anymore");
}

How can I represent this nested if else statement in a UML sequence diagram? Is it possible to do so? Or is a communication diagram better in this case?

like image 207
llamaro25 Avatar asked Oct 25 '25 02:10

llamaro25


1 Answers

Well, you can do that with a fragment in a SD like

enter image description here

As you can see it's geeting crowded soon and the code is more clear than that. Don't be tempted to start graphical programming. SDs are here to give an overview of collaborating objects. Leave the rest to coders and eventually provide some pseudo code.

An AD delivers a more business oriented aspect:

enter image description here

like image 161
qwerty_so Avatar answered Oct 26 '25 19:10

qwerty_so