2

How can I design a Decision node with three outgoing edges and else guard?

what I'd like is - 3 outgoing edges from decision node 'test?'

enter image description here

@startuml

start
:dd;
if (test?) then (a)
  :A;
else if (b)
  :B;
else (c)
  :C;
endif
:wertz;
:dewe;
end

@enduml
Christophe
  • 68,716
  • 7
  • 72
  • 138
frag siri
  • 31
  • 4
  • Welcome, what have you tried so far? – albert Feb 17 '21 at 10:28
  • thx for your response, enclosed my example - but this is not working as it is supposed to.. i'd like 3 edges going out from "test?" `code` start :dd; if (test?) then (a) :A; else if (b) :B; else (c) :C; endif `code` – frag siri Feb 17 '21 at 12:31
  • Please add your `plantuml code` to the question not as a separate comment. – albert Feb 17 '21 at 12:45
  • You are looking for a possibility to show a switch / case statement. I don't know a real answer for it but did you look at an Activity diagram like in the answer of https://stackoverflow.com/questions/32297292/is-there-any-switch-case-in-uml-use-case-specification/32299806 or to the way it is shown in the answer of https://stackoverflow.com/questions/22067090/how-do-i-draw-a-switch-statement-in-a-graphical-design – albert Feb 17 '21 at 13:00
  • yeah I did - don't think this is the right approach :-( – frag siri Feb 17 '21 at 13:26

3 Answers3

2

For that you can use several else allowed by the 'old' syntax of activities :

@startuml
(*) --> if "" then
  --> [[priority = 1]] "A"
else
  --> [[priority = 2]] "B"
else
  --> [[else]] "C"
endif
@enduml

enter image description here

Note it is not possible to directly use ]] nor \]], both producing a syntax error, so I had to use ] to close the bracket

bruno
  • 32,421
  • 7
  • 25
  • 37
2

this is another solution proposed in the PlantUML Q&A: enter image description here

@startuml
start
switch (test?)
case ( condition A )
  :Text 1;
case ( condition B ) 
  :Text 2;
case ( condition C )
  :Text 3;
case ( condition D )
  :Text 4;
endswitch
stop
@enduml
Leandro Maro
  • 325
  • 1
  • 12
0

A similar requirement for "Switch or multiple else branches" was discussed in the PlantUML Q&A, and they suggested the following approach which also worked for me:

@startuml
start
if (condition A) then (yes)
  :Text 1;
elseif (condition B) then (yes)
  :Text 2;
  stop
elseif (condition C) then (yes)
  :Text 3;
elseif (condition D) then (yes)
  :Text 4;
else (nothing)
  :Text else;
endif
stop
@enduml 
Till Kuhn
  • 1,054
  • 11
  • 17