[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I'd give my right arm for a continue statement
- From: Steve Litt <slitt@...>
- Date: Thu, 27 Jan 2011 15:33:28 -0500
On Thursday 27 January 2011 11:42:13 Roberto Ierusalimschy wrote:
> > > I believe that this "break N" will kill code readability as sure as
> > > "goto" would.
> >
> > Yeah, I would get lost pretty quick! Named labels would help [...]
>
> If that could save Steve's right arm, we like the idea of break with
> labels.
>
> In Lua, we cannot have traditional labels, because the syntax "foo:"
> already has a different meaning. Instead, a simple syntax would be to
> add labels only to "do end" blocks, for instance like this:
>
> do :label:
> ...
> end
>
> Then, a continue could be written like here:
>
> while cond do
> do :process_item:
>
> break :process_item:
>
> end
> end
Thanks Roberto,
From my perspective, the preceding has little advantage over putting the stuff
from break :process_item to end in an if statement -- both involve an extra
level of nesting.
My right arm is a little safer these days due to the special iterator user
hack I suggested a week ago. Since then it's been refined, shortened, made a
little more Lua like, and tested in simple situations. When I learn modules it
I'll packaged as a module, after which everyone else will probably improve it
to the point that it will end up being practical and perform reasonably.
It is, however, nice to have an option granted by the language itself, and in
performance critical situations I'll probably use your labeled break rather
than a customized iterator.
Thanks
SteveT
Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt