lua-users home
lua-l archive

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


> This is all so kinf of wierd just to circumvent continue? Whats so bad
> a plain continue? Or is just a arbitrary grown history of refusal
> without a r real deep reason?

We already explained our reasons. And labeled breaks is nothing
wierd. It is an old and well-understood control structure.


> Personally I'm coding for 20 years now, for several years I learned with
> this kind of toy-problems, mini projects,etc. I never used continue,
> didn't even know it existed.  Then at some point (also with the dawn
> of the internet in large scale) I started to analyze code of others,
> and have seen how they use 'continue' to make code thats better than I
> used to, less intendation blocks, less temporary variables, more easy to
> maintain. Since then I'm used to use it, and still find it akward Lua
> forces me not to.

This explains a lot. As you, most people ask for 'continue' because
they learned to use it from other languages. People do not ask for
labeled breaks because few languages offer it, and so many people have
not yet learned to use it.

In Lua, we favor generic and powerful constructs. Actually, a 'goto'
would be almost perfect.  But its interaction with variable scoping
is quite confusing in a language with first-class functions like Lua.
Labeled breaks seem the next best thing, as it allows any forward goto
that does not enter a variable scope.

The current source for 5.2 uses 2 continues plus 16 gotos. All of them
could be replaced by labeled breaks, except one that is used inside a
switch to jump to the default case. (Several gotos in the source would
be unnecessary in Lua, as they are used to emulate tail recursion; but
anyway they could be replaced by labeled breaks plus an infinite while.)

-- Roberto