lua-users home
lua-l archive

Re: I'd give my right arm for a continue statement

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


On 2011年1月27日, Sean Conner wrote:
>
> 	x = 0;
> 	do
> 	{
> 	 body1();
> 	 if (x < 30) continue;
> 	 body2();
> 	 x++;
> 	} while(x < 50);
>
> 		x = 0;
> 	CONTINUE:
> 		body1();
> 		if (x < 30) goto CONTINUE;
> 		body2();
> 		x++;
> 		if (x < 50) goto CONTINUE;
No, that should be:
 		x = 0;
 	start:
 		body1();
 		if (x < 30) goto CONTINUE;
 		body2();
 		x++;
	CONTINUE:
 		if (x < 50) goto start;
> If you keep the similar behavior of "continue" in C into Lua, then:
Note that there is a significant difference in the scoping rules between C
and Lua:
	do {
		int i;
	} while (f(i)); // ERROR: i is not in scope
	repeat
		local i
	until f(i) -- ok: i is in scope
And this difference is one of the reasons that the hypothetical `continue`
would be more awkward in Lua than in C.
Tony.
-- 
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.

AltStyle によって変換されたページ (->オリジナル) /