wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
225 stars 30 forks source link

maybe we need the "continue" #634

Open PhoenixZeng opened 6 years ago

PhoenixZeng commented 6 years ago

as the title not break the loop but skip the code under that on loop

i try use the skip but it is not this mean .and it make i think skip is unuseful. how to use the skip?

Frotty commented 6 years ago

Please see the manual regarding skip https://wurstlang.org/manual.html#skip It is not related to loops.

Regarding continue, we currently aren't planning on adding such a construct. Using continue anywhere else than the beginning of a loop can easily develop into an anti-pattern and produce hard to read code. Usually you can achieve more desirable results by the use of closures and lists. Perhaps add some examples of loops you want to make, and we can discuss if it makes sense or can be done in a different way.

In any case, you can work around this yourself, of course.

var continue = true
while continue and
    if x < 10
        if x mod 2 == 0
            break

         add(x)
    else
        continue = false
peq commented 6 years ago

We could add continue. In my opinion it's not really necessary, but there are some cases where it makes code more readable.

It's not that easy to translate to Jass, though.