[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [patch] continue statement
- From: Chris Marrin <chris@...>
- Date: Mon, 12 Sep 2005 11:06:37 -0700
Shannon Stewman wrote:
On Mon, Sep 12, 2005 at 06:47:34PM +0200, Wolfgang Oertl wrote:
I find that without a "continue" statement some loops soon have
deeply nested if/else statements in them. This patch adds
them to Lua 5.1-alpha. It's also on the PowerPatches page of
the Lua wiki.
Here is another example where a standard way to do non-local exit would
help. The syntax was proposed in
http://lua-users.org/lists/lua-l/2005-08/msg00357.html
Javascript (and others) do this with labelled break and continue. It
lets you do this:
outer_loop:
for(i = 0; i < 10; i++) {
for(j = 0; j < 10; j++) {
if (f(i,j) > 0) break; // break out of inner loop
if (g(i,j) > 0) continue outer_loop; // restart outer loop
if (h(i,j) > 0) break outer_loop; // break out of outer loop
}
}
It's nice looking syntax IMHO. And it's very safe since the label must
be on a looping statement or a compile time error is generated.
--
chris marrin ,""$,
chris@marrin.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'