lua-users home
lua-l archive

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


On Jun 25, 2014, at 12:21 PM, Sean Conner <sean@conman.org> wrote:

> 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

With my continue patch this example gives the following error:

lunia: cont.lua:6: <goto continue> at line 3 jumps into the scope of local 't'

(Hmm, I should probably change the wording of that to just "<continue> at line...")


> 	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.

This example, of course, will fail if x.y.t is not defined before you actually enter the repeat loop. However, that would pretty much be the case no matter which language you would use. ;)

~pmd