lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Wednesday, January 8, 2014, Jonas Thiem wrote:
Since there is now a working goto in Lua, I suppose there is no longer
any technical reason why there is no continue.

In case that's true, I would like to point out that goto as a
continue-replacement isn't very nice:

It needs twice the lines (goto statement + label), and you need to
make up a unique jump label per loop if you got multiple loops in a
function with such a continue workaround.

Also, you can easily mix up your jump labels and suddenly jump into
one of the other loops and generate non-obvious, huge bugs with that.

What about natively supporting continue in an upcoming Lua version? I
would be using it a lot, I do in all other programming languages which
usually have it.


I find it interesting that your experience is no doubt true, while at the same time mine is that I don't ever miss it. That is, I wonder if you're programming in a different way than I am or if your problems are fundamentally different than mine. 

I wrote previously that I use `goto continue` all of the time. What I didn't write is that... more than half the time that I use it, it ends up getting refactored out of existence. 

It's much like how `repeat until x` was never missed, until I started using it in "main" loops.

There is no critique here. I'm just wondering if the lack if continue is sort of... A part of the language that might suggest a different pattern to solve the same problem, and to do it elegantly. Or, is it the case that there are problems that are very hard to solve because it's not there.