Join 2 actions boxes from separate conditions statements

0 votes
asked Apr 2, 2023 in Question / help by anonymous

I have this simple flow with if-elseif conditions:

@startuml
:Init;
if (cond 1) then (yes)
 :action 1;
 detach
elseif (cond 2) then (yes)
 :action 2;
 detach
elseif (cond 3) then (yes)
 :action 3;
 if (cond 3-1) then (yes)
  :action 2;
  detach
 else
  :action 3-1;  
  detach
 endif
 detach
else
 :action 4;
 stop
endif
@enduml

As you see, cond2 and cond3 can lead to the same action2, but they are specified twice.

Is there a way to somehow move out cond2 box from the conditionals and point to that reference from them instead of creating 2 equal boxes?

1 Answer

0 votes
answered Apr 2, 2023 by The-Lu (63,000 points)

Hello A., and all,

Here is a proposal using `label` and `goto`, as:

@startuml
:Init;
if (cond 1) then (yes)
 :action 1;
 detach
elseif (cond 2) then (yes)
 label dummy
 label dummy
 label dummy
 label dummy
 label a2
 :action 2;
 detach
elseif (cond 3) then (yes)
 :action 3;
 if (cond 3-1) then (yes)
  label dummy
  goto a2
 else
  :action 3-1;
  detach
 endif
else
 :action 4;
 stop
endif
@enduml

It is only on beta version, and not fully operational (with a lot of dummy label!), but: Enjoy,
Regards.

commented Apr 4, 2023 by anonymous
Ok, that works, thanks!
But I have to say it's a bit ugly :)
I was hoping there would be some other way to connect boxes that are in different places, or define a box outside everything and connect to it from the desired places.
...