Please provide the ability to break from loops

+1 vote
asked Nov 30, 2016 in Closed feature request by anonymous
edited Nov 30, 2016

Please provide the ability to break from loops.

 

Today what I have to do is this:

@startuml
start
repeat
  :Test something;
    if (Something went wrong?) then (yes)
      :Alert "Error";
    else
      ->no;
    endif

repeat while (Something went wrong?) is (yes)
->no;
stop
@enduml

6 Answers

+1 vote
answered Dec 6, 2016 by plantuml (183,480 points)
selected Jul 7 by Anthony-Gaudino
 
Best answer

The ability to break loop is a very asked feature.
(See all requests about goto!)

Fortunately, we figure out a way to implement break in repeat loop, as it was slightly easier to do than full goto.
So with last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar
you use the new break keyword, that has the same meaning as in Java/C/C#/C++

For example:

@startuml
repeat
:test something;
if (something get wrong) then (no)
break
endif
:error;
repeat while
:some more;
@enduml

This is really an alpha version: it will probably not work in many cases.
So we need some testers here: thanks to report bugs here.

If we succeed in making this working with repeat loop, we will extend it to other loops, and possibly add continue feature.

0 votes
answered Dec 6, 2016 by Missan (280 points)

Thanks a lot for the update.
I just tried the new version and I got this:

 

It is very nice :)!! Thanks again.

And here is a first feedback : it's not my need but I tried to put a break in the else clause and it broke:

@startuml
repeat
  :Test something;
    if (Something went wrong?) then (yes)
      :Alert "Error";
    else
      break
    endif
repeat while (Something went wrong?) is (yes)
->no;
:Alert "Sucess";
@enduml

An error has occured : java.lang.UnsupportedOperationException: class net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond.FtileIfWithLinks

Hope this helps!

Regards

commented Dec 6, 2016 by plantuml (183,480 points)
Yes, it helps!
Here is a new beta that partially solved this https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

However, the "break" link is now crossing other elements : this is where the real difficulties start... We have to think about all this.

Thanks again
0 votes
answered Dec 7, 2016 by Missan (280 points)

I just found 3 regressions (one major and two minor) :

1/ It impossible to add note almost everywhere close to the repeat:

@startuml
start
repeat
 ### It won't work from here...
  note left : A note
  :Test something;
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    :Alert "Error";
repeat while (Something went wrong?) is (yes)
->no;
:Alert "Sucess";
 ### ... To here
stop
@enduml

2/ There is no padding if there is long text in a step:

@startuml
start
repeat
  :Test something;
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    :Alert "Error with long text";
repeat while (Something went wrong?) is (yes)
->no;
:Alert "Sucess";
stop
@enduml

OR

@startuml
start
repeat
  :Test something;
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    :Alert "Error";
repeat while (Something went wrong with long text?) is (yes)
->no;
:Alert "Sucess";
stop
@enduml

3/ There is an issue with arrows. You can get up to 3 arrow on the same line if add a label to the line:

@startuml
start
repeat
  :Test something;
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    ->NOK;
    :Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes)
->no;
:Alert "Sucess";
stop
@enduml

Around the "NOK"

Hope this helps!

commented Dec 7, 2016 by plantuml (183,480 points)
It helps!
First point is solved in last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar
We're still working on others.
Thanks
0 votes
answered Dec 7, 2016 by Missan (280 points)

Thanks for the update.

1/ Comments

I think it is partially working. This piece of code produces a strange result:

@startuml
start
repeat
  floating note left : A note
  :Test something;
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    ->NOK;
    :Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes)
->no;
:Alert "Sucess";
stop
@enduml

 

More over is still buggy in the following locations:

@startuml
start
repeat
  :Test something;
  ### Buggy from here...
  floating note left : A note
    if (Something went wrong?) then (no)
      :OK;
      break
    endif
    ->NOK;
    :Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes)
->no;
### ... to here
:Alert "Sucess";
stop
@enduml

An error has occured : java.lang.UnsupportedOperationException: class net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileWithNoteOpale

Good luck :)!

commented Dec 8, 2016 by plantuml (183,480 points)
OK, here is a new beta
https://dl.dropboxusercontent.com/u/13064071/plantuml.jar
Right now, we are focusing on crash / strange drawing.
We'll work on "padding" issue later, when/if everything will be working.
So do not hesitate to post new examples, it really helps : we do not have time to test our code :-)
commented Dec 15, 2016 by plantuml (183,480 points)
We have fixed the padding issue in last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar
+1 vote
answered Mar 29, 2017 by plantuml (183,480 points)

It took us a very long time, but since this is a very asked feature, we give it a chance.

With last beta https://www.dropbox.com/s/koo42q3d9gxw288/plantuml.jar?dl=0

You can have now:

@startuml

start

repeat
  :read data;
  :generate diagrams;
backward:This is backward;
repeat while (more data?)

stop

@enduml

This is a first version : the "backward" stuff can only be on one line.

Very few tests have been done, so feedback is welcome!

In future, we may accept several "backward" activify, but we will never be able to add complex structures (like if, while...) in the backward itself.

 

0 votes
answered Mar 31, 2017 by Missan (280 points)

Hello,

 

I just tested last version and it works like a charm with the given example.

 

Thanks a lot for the update.

I'll try to add comments and stuff like that when I'll have time.

 

Thanks!

...