Sequence diagrams: alt / else / opt fragments

Sequence diagrams: alt / else / opt fragments

puml.online

简介 / Introduction

The alt / else / opt fragments in sequence diagrams express conditional branching and optional interactions. Both PlantUML and Mermaid support these fragments, but with slightly different syntax details. This article compares both using the same scenario.

PlantUML version

1
2
3
4
5
6
7
8
9
10
11
@startuml
Alice -> Bob: operation request
alt authorization succeeded
Bob -> Carol: forward request
Carol --> Bob: response data
else authorization failed
Bob -> Dave: log error
Dave --> Bob: error acknowledgment
end
Bob --> Alice: operation result
@enduml

PlantUML uses alt / else / end to form a complete conditional block. Multiple else branches are supported, with guards written on the same line as alt.

Mermaid version

1
2
3
4
5
6
7
8
9
10
sequenceDiagram
Alice->>+Bob: operation request
alt authorization succeeded
Bob->>+Carol: forward request
Carol-->>-Bob: response data
else authorization failed
Bob->>+Dave: log error
Dave-->>-Bob: error acknowledgment
end
Bob-->>-Alice: operation result

Mermaid’s alt / else structure mirrors PlantUML closely. Indentation marks nesting and end closes the block.

对比 / Side-by-side

Feature PlantUML Mermaid
Conditional keywords alt / else / end alt / else / end
Multiple branches multiple else multiple else
Guard condition alt condition on same line alt condition on same line
Loop fragment loop loop
Optional fragment opt opt
Indentation required free-form recommended

小结 / Wrap-up

Both engines share nearly identical fragment syntax for alt / else / opt / loop. PlantUML is more flexible with nested conditions and guard expressions; Mermaid is more concise and readable. Choose based on your team’s toolchain and editor support.

  • Title: Sequence diagrams: alt / else / opt fragments
  • Author: puml.online
  • Created at : 2026-10-15 09:00:00
  • Updated at : 2026-10-19 01:07:19
  • Link: https://puml.online/blog/sequence-diagram-alt-vs-else-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Sequence diagrams: alt / else / opt fragments