[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: [PATCH] experimental php-like 'break N' to break across multipleloops
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Wed, 1 Nov 2006 11:45:28 -0500
We would just have to tag loops and use that tag in break statements. Example:
local prefix = "loop"
local n = 2
while[prefix..1] i<=10 do
for[prefix..2] j=1,10 do
if foo then
elseif bar then
break -- Would trigger a runtime error, no loop has nil tag
Simples "while", "for" and "break" would be syntactic sugars for "while[nil]", "for[nil]", "break nil" respectively. "nil" as a loop label match only "nil" as a break parameter, no wildcard. I used brackets because parenthesis after while/for/repeat would collide with current syntax. For the break it feels more natural to not have any parenthesis, but we could enforce () or  with existing sugars for string and array constructors.
I think it's a nice addition. It probably needs internal Lua support because of the tagging of loops, and error detection if break parameter match no current tag.
De : email@example.com [mailto:firstname.lastname@example.org] De la part de Paul Hudson
Envoyé : 1 novembre 2006 09:43
À : 'Lua list'
Objet : RE: [PATCH] experimental php-like 'break N' to break across multipleloops
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.
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.
[mailto:email@example.com] On Behalf Of Karel Tuma
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.
while foo do
while bar do
if baz then eek() break 2 end