lua-users home
lua-l archive

Re: Why do we have ipairs?

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


It was thus said that the Great David Demelier once stated:
> Le 11 juin 2014 10:30, "Axel Kittenberger" <axkibe@gmail.com> a écrit :
> >
> > But a switch statement in most script languages (like in Javascript) is
> syntactic sugar for if/else! That has always been the argument from the Lua
> team to why there is no switch statement in Lua. Not like for example in C
> where it is in fact a computed goto.
> >
> 
> Unfortunately it still does not explain why there is no continue in Lua but
> break exists. This is one of my major hate.
 This is a topic that pops up from time to time, such as back in 2010:
http://lua-users.org/lists/lua-l/2010-02/msg00491.html
 The result seems to be that continue in the presence of repeat/until is
undefined. The example given:
	repeat
	 if cond then continue end
	 local t = 1
	 ...
	until t == 4
"continue" will skip ahead to the conditional, but when cond is true, then t
is undefined (locals in the repeat/until scope don't go out of scope until
after the until statement). You might say that's okay, t returns nil, but
what about this?
	repeat
	 if cond then continue end
	 x = { y = { t = 1 }
	 ...
	until x.y.t == 4
you'll error out with an undefined reference (contrived, yes). That was
apparently enough of a concern to keep continue out of Lua.
 -spc

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