lua-users home
lua-l archive

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

On Wed, Nov 01, 2006 at 03:43:20PM +0100, Paul Hudson wrote:
> I'm not sure this is needed, but if other people disagree :) then I think
> the Perl-esque idea of breaking out to a labelled statement is the way to
> go.

yep. what about goto? thats named scope too :)
spaghetti construct will remain spaghetti construct, no matter the
circumstances. (named labels, gotos, numbered breaks...).
named scopes are easier to follow in complicated cases.

> The problem with using numeric levels is that refactoring the code and
> changing the number of nested scopes means looking for and changing any
> "break N" statements, which I think is a likely source of tricky-to-debug
> errors.

agreed. people must think of it like "skip this number of indentation
levels" (in most cases where loops follow each other). instead of
'reference to named scope which we no longer use'. refactoring
mutli-scope constructs is always tough - starting with locals visibility.

when break N is used the loops are almost always inseparable
(for example, two dimensional array search), otherwise
there would be other way around than using spaghetti code (excluding lambda)


> -----Original Message-----
> From:
> [] On Behalf Of Karel Tuma
> hi listers,
> i've found myself doing lot of miserable things today, due to inability of
> lua
> to simply break out of multiple nested breakable scopes in one statement.
> finding nothing useful in powerpatches archive i wrote this rather naive
> and unintrusive patch - so there is generally no reason why it shouldn't
> work,
> but i've tested it extensively only with various for/while nested loops.
> use:
> while foo do
> 	while bar do
> 		if baz then eek() break 2 end
> 	end
> end