1.5.8 Representing if/else if Statements in Activity Diagrams

An if/else if Chain Becomes a Sequence of Decisions

A C# if/else if chain checks conditions in order.

A UML activity diagram can represent that same behavior with decision nodes connected along the false path.

Consider:

if (goals >= 3)
{
    System.Console.WriteLine("Three or more goals.");
}
else if (goals == 2)
{
    System.Console.WriteLine("Two goals.");
}
else if (goals == 1)
{
    System.Console.WriteLine("One goal.");
}
else
{
    System.Console.WriteLine("No goals.");
}

The key behavior is:

Model the First Condition First

The first C# condition is:

goals >= 3

A diagram decision can be phrased:

Are there at least 3 goals?

Conceptually:

        Are there at least 3 goals?
                   ◇
                 /   \
           [true]     [false]
             |           |
             v           v
Display three-or-more   next decision

The false path does not immediately mean the final else.

It leads to the next else if condition.

Add the Second Decision on the False Path

The next C# condition is:

goals == 2

The activity flow becomes:

Are there at least 3 goals?
          ◇
        /   \
   [true]   [false]
      |         |
      v         v
Display 3+   Are there exactly 2 goals?
                   ◇
                 /   \
            [true]   [false]
               |         |
               v         v
        Display 2     next decision

This shows that the second question is evaluated only when the first question was false.

Continue the Chain for Additional Conditions

For:

else if (goals == 1)

add another decision on the false path:

Are there exactly 1 goal?

Now the logical sequence is:

goals >= 3?
   ├─ true  → display 3+
   └─ false → goals == 2?
                 ├─ true  → display 2
                 └─ false → goals == 1?
                               ├─ true  → display 1
                               └─ false → display 0

The final false path represents the final else.

The Diagram Must Preserve Top-to-Bottom Evaluation

C# evaluates the chain in source order.

The UML model should preserve the same order.

Do not rearrange the decisions merely because another visual arrangement looks more balanced.

If the source asks:

  1. at least 3?
  2. exactly 2?
  3. exactly 1?

the activity diagram should represent that same decision sequence.

Only One Outcome Path Is Selected

Suppose:

goals = 3

The first question:

Are there at least 3 goals?

is true.

The diagram follows that true path.

The later decisions are not reached.

The activity diagram should not imply that the process continues through every remaining decision after selecting an outcome.

Rejoin the Paths After the Selected Action

If all branches later continue with the same process, the outcome paths can rejoin.

Conceptually:

     decision chain
   /      |      \
action  action  action
   \      |      /
      continue

The exact visual layout can vary.

The meaning should be clear:

The Final else Is the Remaining False Path

In C#:

else
{
    System.Console.WriteLine("No goals.");
}

there is no new Boolean expression.

Therefore the activity diagram does not need another decision node for the final else.

The final action is reached when every earlier condition was false.

Do Not Represent else if as Parallel Decisions

An if/else if chain is sequential.

This is misleading:

       start
     /   |   \
decision decision decision

That picture suggests the questions can all be evaluated independently.

The actual C# behavior is:

decision 1
   ↓ false
decision 2
   ↓ false
decision 3

Each later condition depends on the earlier conditions being false.

Do Not Represent the Chain as a Nested if Yet

A UML activity diagram may visually contain several decision nodes.

That does not mean the source uses nested if statements.

For the current chain:

if (...)
)
{
}
else if (...)
)
{
}
else if (...)
)
{
}
else
{
}

the decisions represent one ordered if/else if structure.

Nested conditional syntax is taught separately in CO-045.

Use Plain-Language Decision Questions

For C#:

goals >= 3

a useful UML question is:

Are there at least 3 goals?

For:

goals == 2

use:

Are there exactly 2 goals?

The diagram should help a learner understand the logic, not require them to decode source syntax inside the decision node.

Compare the Diagram Back to the C# Chain

For every decision node, identify:

  • the matching C# condition;
  • the true path;
  • where the false path goes next.

For every action, identify:

  • which branch selected it;
  • whether later conditions should be skipped.

A trace for:

goals = 2

should read:

At least 3? → false
Exactly 2?  → true
Display "Two goals."
Skip remaining branches
Continue after chain

The UML and C# are aligned when they tell the same execution story.

The Main Visual Pattern

An if/else if chain is modeled as:

decision
  ├─ true  → action
  └─ false → next decision
                 ├─ true  → action
                 └─ false → next decision or final else

That pattern preserves the defining behavior of the C# structure: