if condition and goto/label in activity diagram

0 votes
asked Feb 7 in Question / help by vietnamesebushes

@startuml test

start

if ( condition_1then (true)

    if ( condition_2 then (true)  

        if ( condition_3 then (true)

            if ( condition_4 then (true)

                :do something;

            endif

        else (false)

            label false_handling

            :something is wrong here;

        endif

    else (false)

        goto false_handling

    endif

else (false)

    goto false_handling

endif

stop

@enduml


The intention of this code is to perform a series of nested conditional checks. If all conditions (condition_1condition_2condition_3, and condition_4) are true, a specific action (do something) is executed. If any condition is false, the flow jumps to a label (false_handling) where an error message (something is wrong here) is displayed.

But the flow chart isnt being displayed what I want to see.
 

1 Answer

0 votes
answered Feb 9 by The-Lu (79,040 points)

Hi V.,

From:

Here is a proposal, changing all `if` to begin with `false`, as:

@startuml test
start
if ( condition_1) then (false)
  label dummy
  label dummy
  label dummy
  label l
  :something is wrong here;
else (true)
  if ( !condition_2 ) then (false)
    label dummy
    goto l
  else (true)
    if ( condition_3 ) then (false)
      label dummy
      goto l
    else (true)
      if ( condition_4 ) then (false)
        else (true)
          :do something;
      endif
    endif
  endif
endif
stop
@enduml

Enjoy,
Regards,
Th.

...