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]


It was thus said that the Great Tony Finch once stated:
> 
> > 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
 It doesn't seem right to me that until has access to the inner scope of
the loop; isn't that violating the scope or something like that? 
 Also, is the issue with coninue this?
	repeat
	 code()
	 if blah then contiue end
	 local i
	 more_code()
	until i
 Or with this?
	repeat
	 local i
	 code()
	 if blah then continue end
	 more_code()
	until i
 Or both? I'm not sure what the problem is. In C, a continue in a "do ...
while" skips the conditional test. Is the issue the conditional test? Or
the creation of the locally scoped variable? 
 -spc

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