|
12345
|
Hi all,
I'd give my right arm for a continue statement within a loop. I know it's
lousy programming technique, but when you're counting but not processing blank
lines, it comes in very handy so you don't need to put the majority of a loop
in a very long if statement.
Have any of you found convenient ways to simulate a continue statement in Lua?
Thanks
SteveT
Steve Litt
Recession Relief Package
http://www.recession-relief.USTwitter: http://www.twitter.com/stevelitt
|
|
On Sat, Jan 22, 2011 at 10:00 AM, Steve Litt < [hidden email]> wrote:
> I'd give my right arm for a continue statement within a loop. I know it's
> lousy programming technique,
This one comes up frequently ;)
E.g.
http://lua-users.org/lists/lua-l/2010-11/msg00479.htmlfor an interesting generalization.
I think the usu way of doing it is:
while condition do repeat
if something then break end --- breaks the repeat, acts like continue
...
until true; end
Of course, this means that it's hard to actually break out of the while...
steve d.
PS. I wouldn't necessarily think of 'continue' as bad
|
|
On Sat, Jan 22, 2011 at 01:18, steve donovan < [hidden email]> wrote:
> On Sat, Jan 22, 2011 at 10:00 AM, Steve Litt < [hidden email]> wrote:
>> I'd give my right arm for a continue statement within a loop. I know it's
>> lousy programming technique,
>
> This one comes up frequently ;)
>
> E.g.
>
> http://lua-users.org/lists/lua-l/2010-11/msg00479.html>
> for an interesting generalization.
>
> I think the usu way of doing it is:
>
> while condition do repeat
> if something then break end --- breaks the repeat, acts like continue
> ...
> until true; end
>
> Of course, this means that it's hard to actually break out of the while...
>
> steve d.
>
> PS. I wouldn't necessarily think of 'continue' as bad
>
>
I'm often cursing the lack of a continue statement as well. Really
curious why it's missing.
--
Sent from my toaster.
|
|
I also thought I should make a public cross off table, when coding any
algorithmn like I'm used to for decades and then suddendly realize
"argh, cant use continue", and have to do some kind of wierd work
around, add a cross to it.
There are some work arounds, none is perfect, and all of them have in
common, they effectively obfustucate your code making it more
difficult to read. Sometime the if ... then for the rest of the loop
works and only makes an otherweise unnecessary intendation, but
sometimes you need a "true" continue.
Yes
[Loop] repeat
...
break; --- this is actually a continue!
....
until true end;
Is the best workaround with the least obfustication. Dont forget to
add the "break is actually continue" comment, otherwise anoter human
will be puzzled without end.
If you are in a project where you can patch your lua, a continue patch
is easily worth it. If you are in a project (like me) where you have
to do what the standard distros give you, you'll have to keep
workarounding. It continues to be an annoyance but it is no show
breaker.
On Sat, Jan 22, 2011 at 9:00 AM, Steve Litt < [hidden email]> wrote:
> Hi all,
>
> I'd give my right arm for a continue statement within a loop. I know it's
> lousy programming technique, but when you're counting but not processing blank
> lines, it comes in very handy so you don't need to put the majority of a loop
> in a very long if statement.
>
> Have any of you found convenient ways to simulate a continue statement in Lua?
>
> Thanks
>
> SteveT
>
> Steve Litt
> Recession Relief Package
> http://www.recession-relief.US> Twitter: http://www.twitter.com/stevelitt>
>
>
|
|
On Sat, 2011-01-22 at 01:22 -0700, HyperHacker wrote:
> I'm often cursing the lack of a continue statement as well. Really
> curious why it's missing.
You can find a short answer here: http://www.luafaq.org/#T1.26
|
|
On Sat, Jan 22, 2011 at 12:23, steve donovan < [hidden email]> wrote:
> On Sat, Jan 22, 2011 at 11:13 AM, Michal Kottman < [hidden email]> wrote:
>> You can find a short answer here: http://www.luafaq.org/#T1.26> Although it's not the whole story, and should be updated.
> The best answer is by Roberto, quoted by David Manura in this post:
> http://lua-users.org/lists/lua-l/2010-11/msg00479.htmlSorry, but: yuk! :-(
I believe that this "break N" will kill code readability as sure as
"goto" would. I can understand people wanting continue (though I don't
particularly want it, and live fine without), but this jumping through
scopes?..
Alexander.
|
|
On Sat, Jan 22, 2011 at 11:31 AM, Alexander Gladysh < [hidden email]> 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
while C1 do
while C2 do
if C3 then continue C1_loop end
end
end :C1_loop
The labels are also useful at the end of a big set of nested loops -
careful people often comment loop ends, anyway.
This is not a serving suggestion (as they say on packages) just an
indication of how the idea would work - actual syntax is always up for
debate.
steve d.
|
|
""
> This is not a serving suggestion (as they say on packages) just an
> indication of how the idea would work - actual syntax is always up for
> debate.
>
> steve d. ""
I am very weak with C++ but do you think that named labels in
conjunction with a C++ "using" like statement would give people finer
grain control over scope. Could something like this be implemented
through meteatables?
It might diffuse the module debate as well. With named labels/using
could people not just choose scope and include/require/import/dofile etc
other files directly into the namespace the programmer has set?
-Patrick
|
|
The sarcastic story as far I read it, the lua gods are waiting for a
scintillation how to solve it in a general way. So far this has not
yet happened. Maybe the holy ghost does its job one day, and we going
to see an implementation that baffles us all or maybe we just admit
that standard continue is a good compromise between more flow control
while avoiding the jumping hell goto's open. I can understand and
respect the wish to keep a language as simple as possible, but
standard continue make many loops simpler if used right and the
applications more maintainable. Maybe it would be the sugar 5.2 needs
to make it attractive.
BTW. I'm against break N or break [-N], if N is an integer and not a
label. But I could accept continue [n] where n indicates the amount of
cycles to jump forward, that is the number of times to call next(). 0
is redo, 1 normal continue, 2 a skip etc.
On Sat, Jan 22, 2011 at 10:23 AM, steve donovan
< [hidden email]> wrote:
|
|
""On 01/22/2011 01:57 PM, Axel Kittenberger wrote:
The sarcastic story as far I read it, the lua gods .................""
Just wanted to mention that Lua has been given to us and that Luiz and
Roberto volunteer their time.
Hope you can be sensitive to this
-Patrick
|
|
Axel Kittenberger < [hidden email]> writes:
> or maybe we just admit that standard continue is a good compromise
> between more flow control while avoiding the jumping hell goto's open
"ymmv"
I don't use continue at all (though I use break all the time) -- though
I of course have always known about it, it's just not a habit I ever
really got into with C -- and I don't seem to miss it, nor do I seem to
end up using goto as an alternative.
So I tend to roll my eyes a lot when reading this threads, with people
constantly swearing their eternal allegiance to continue. As far as I
can see, it's not really all that important, and certainly not worth the
amount of hot air expended over it...
-miles
--
Acquaintance, n. A person whom we know well enough to borrow from, but not
well enough to lend to.
|
|
I use continue all the time.
It allows you to avoid excessive nesting of code / if statements in a loop.
For that reason, it's very useful.
On 23/01/2011 9:38 a.m., Miles Bader wrote:
> Axel Kittenberger< [hidden email]> writes:
>> or maybe we just admit that standard continue is a good compromise
>> between more flow control while avoiding the jumping hell goto's open
> "ymmv"
>
> I don't use continue at all (though I use break all the time) -- though
> I of course have always known about it, it's just not a habit I ever
> really got into with C -- and I don't seem to miss it, nor do I seem to
> end up using goto as an alternative.
>
> So I tend to roll my eyes a lot when reading this threads, with people
> constantly swearing their eternal allegiance to continue. As far as I
> can see, it's not really all that important, and certainly not worth the
> amount of hot air expended over it...
>
> -miles
>
--
Adrien de Croy - WinGate Proxy Server - http://www.wingate.com
|
|
On 1/22/11, Miles Bader < [hidden email]> wrote:
> Axel Kittenberger < [hidden email]> writes:
>> or maybe we just admit that standard continue is a good compromise
>> between more flow control while avoiding the jumping hell goto's open
>
> "ymmv"
>
> I don't use continue at all (though I use break all the time) -- though
> I of course have always known about it, it's just not a habit I ever
> really got into with C -- and I don't seem to miss it, nor do I seem to
> end up using goto as an alternative.
>
> So I tend to roll my eyes a lot when reading this threads, with people
> constantly swearing their eternal allegiance to continue. As far as I
> can see, it's not really all that important, and certainly not worth the
> amount of hot air expended over it...
>
> -miles
>
> --
> Acquaintance, n. A person whom we know well enough to borrow from, but not
> well enough to lend to.
>
>
<sarcasm>I especially like comments like "other languages have this
feature". It really sells the idea... </sarcasm>
|
|
I found it interesting that continue is used in 55 places in Lua 5.1.4 ;)
It is one thing I really miss in Lua too.
|
|
On Sat, Jan 22, 2011 at 10:06 PM, dcharno < [hidden email]> wrote:
> I found it interesting that continue is used in 55 places in Lua 5.1.4 ;)
IIRC, at least some of those uses of continue simulate tail-calls
(which Lua implements but C does not). When I ported the string
library to Lua [1], the `continue` statements there were more
appropriately re-expressed in Lua as tail calls.
[1] http://lua-users.org/wiki/StringLibraryInLua
|
|
On 01/23/2011 12:00 AM, David Manura wrote:
> On Sat, Jan 22, 2011 at 10:06 PM, dcharno< [hidden email]> wrote:
>> I found it interesting that continue is used in 55 places in Lua 5.1.4 ;)
>
> IIRC, at least some of those uses of continue simulate tail-calls
> (which Lua implements but C does not). When I ported the string
> library to Lua [1], the `continue` statements there were more
> appropriately re-expressed in Lua as tail calls.
>
> [1] http://lua-users.org/wiki/StringLibraryInLuaBefore the hate mate starts rolling in, I'll say I meant it partially as
a joke and partially as a way of saying continue is a tool that's useful
in some cases. I'm sure all of the continue statements could be removed
from any specific source tree.
|
|
Axel Kittenberger < [hidden email]> writes:
> The sarcastic story as far I read it, the lua gods are waiting for a
> scintillation how to solve it in a general way.
I seem to remember that this was basically considered a scope problem
since "continue" in a repeat-until, when implemented C-like, was
supposed to reevaluate the loop condition, and the loop condition could
refer to local variables introduced after the call of continue.
My take on this had been that the C behavior is undesirable anyway and
that continue in a repeat-until loop should reiterate _straight_ from
the top of the loop without checking the _finishing_ loop condition.
While not "C-like", this would be much more useful, as well as rendering
the scoping problem irrelevant.
I've seen no comment to that proposal from the Lua gods, but I'd not be
overly surprised if "continue" in the subject line of a posting warrants
an automatic killfile entry by now...
--
David Kastrup
|
|
On 22.01.2011 15:23, steve donovan wrote:
> The best answer is by Roberto, quoted by David Manura in this post:
> http://lua-users.org/lists/lua-l/2010-11/msg00479.htmlThat's a real deal. I find 'continue' and 'break N' both very useful in
certain situations. I think there also were situations where I wanted
'continue N' that would act similar to 'break N'. 'Redo' and 'continue
n' with 'n' indicating the number of iterations to skip are useful too...
Now, to the readability.
The first thing is that 'break' and 'continue' must be separate keywords
for the sake of readability.
I don't think 'break N' would worsen readability much compared to
standard 'break'. You already have to get over one or two ends of IF's
now to find the end of the loop. In many cases nested loops come one
right after another and 'break N' would be almost as readable as simple
'break'. Actually, when 'break N' is needed, it improves readability,
because work-arounds used instead of just shadow the logic.
I like the suggestion of labeled loops, it's certainly more readable,
but it's a serious syntax extension. I gravitate towards something like
this syntax:
for y = 1,10 do
for x = 1, 10 do
break 'y'
end 'x'
end 'y'
The stringy labels should prevent any collisions with operators that follow.
Overall, I consider simple 'continue' to be a safe ground. Any readable
more sophisticated solution I can think of would still include the
'continue' statement.
--
Best regards,
Sergey Rozhenko mailto: [hidden email]
|
12345
|