Switch or multiple else branches for new activity diagram

+5 votes
asked Jun 5, 2013 in To be sorted by anonymous
Is there a way to achieve something like

@startuml
if (Condition) then (default)
...
else (case 1)
...
else (case 2)
...
else (case 3)
...
endif
@enduml

Trying it like this does not work unfortunately, the case 1 and 2 are just replaced by case 3.

1 Answer

0 votes
answered Jun 20, 2014 by plantuml (295,800 points)

Hi,

You can have this:

@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

Sorry we did not document that before!

commented Mar 7, 2019 by anonymous
i tried just like that the other day and it worked :)
commented Jan 10, 2020 by Kien Vu (140 points)
Isn't this just a workaround? I want true multiple choice switch statement like construct. Is that even possible?
commented Apr 28, 2021 by etienne-sf (100 points)
Hello, I also find that having several "else" (or a switch command) would be nice.

I have a processus, where the process can be routed to around 10 possible branches. Having 10 tests is not very readable.

But on can find this as being a luxury: The process can actually be displayed !

Etienne
commented Apr 29, 2021 by The-Lu (74,900 points)

Hello K., E. and all,

From ~V1.2019.5 (20 Apr, 2019), you can use:

@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

If that can help,
Regards,
Th.

...