Help with a repeat while clause.

0 votes
asked Dec 2, 2021 in Question / help by megaxm (120 points)

Hi.
I have to complete the two lines missing, but I don't seem to get around. The stop after "Log Report", and the one "Are there elements in the list2? -> no" should go back to "Listen to Events" and the stop must be removed. Do you have an idea or recommendation of how I can do that. Thanks so much in advance.

Here is the code.

@startuml Diagram

!define LIGHTBLUE

!includeurl https://raw.githubusercontent.com/Drakemor/RedDress-PlantUML/master/style.puml

start

:Queue Handling;

:Publish Events\nnotify-keyspace-events;

if (is publish successful?) then (yes)

  :Subscribe to Events;

  repeat

  repeat

  repeat:Listen to Events;

  repeat while (has a notification arrived?) is (no) not(yes)

  :Check Notification;

  repeat while (Is the notification linked to a sock?) is (no) not(yes)

  :Get name name from the sock;

  :get socks;

  :Check name list1;

  if(Are there elements in the list1?) then (yes)

    :Remove 1st item from list1 and create a sock;

  else (no)

    :Check name list2;

    if(Are there elements in the list2?) then (yes)

      :Remove 1st item from list2 and create a sock;

    else (no)  

      stop

    endif

  endif

  repeat while (Is sock creation successful?) is (yes) not(no)

  :Log Report;

  stop

else (no)

  :<b>Error</b>\n<b>Program Terminates</b>;

  stop

endif

@enduml

commented Dec 5, 2021 by Martin (8,360 points)
edited Dec 5, 2021 by Martin

Plantuml activity diagrams don't really support Goto.   So your best bet with looping back after the "log Report" is another loop.  (I used a While loop for 1 diamond, instead of 2 for a Repeat loop).  Replace the Stop with Detach.

(When I detached the While loop, it left an ugly arrow to nowhere; which I've hidden using  the [hidden] attribute.)

(click diagram for online server)

But I haven't got a good solution to removing your other Stop.  Using Goto looks awful.  I couldn't get backward to be accepted.  Break exits to before Log Report (and looks bad).  I think in this situation you would have to repeat some boxes...

(click diagram for online server)

You could use "skinparam ConditionEndStyle hline" to get rid of the lower diamonds, but I'm not sure it looks better.  It would be nice if there was a way to merge consecutive empty diamonds...

commented Dec 6, 2021 by megaxm (120 points)
Thanks so much. Very much appreciated.
commented Dec 7, 2021 by The-Lu (64,340 points)

Hello all, and  @Martin 

  • Could you post your comment as an answer?
    For more convenience, and following the Q&A.

Or I can create it, just by linking to your comment, as you want...

Regards.

1 Answer

+2 votes
answered Dec 7, 2021 by Martin (8,360 points)

A partial answer, based on my extended comment above.

1) Removing the STOP at the bottom is easy - just wrap everything in another loop.  Initially I used a Repeat loop, but this added a diamond to both the top and bottom of the diagram.  Then I discovered a way to create a detached While loop, which only added the top diamond.

2) I couldn't find a way of removing the other more enclosed STOP.  My suggestion is to refactor by repeating some boxes.

Here is my best attempt:


 

...