lua-users home
lua-l archive

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

>From another current thread, we can see that some people like the
introduction of goto in Lua 5.2 while some others hate it !
Still, I wanted to use that keyword to simulate the missing
"continue", and was surprised that this type of code actually works :

for i=1,10 do
  if i%3 == 0 then goto continue end
  local v = i*2

Maybe it is clear for other people, but it was not for me.
Because in the manual, it is stated "A goto may jump to any visible
label as long as it does not enter into the scope of a local variable.
And it looks that the ::continue:: label is inside the scope of the
"v" variable, declared after the goto.
But right, if there is *any* instruction after the label (except empty
semicolons), the code doesn't compile anymore.
The reference manual could further explain that a label is allowed
just before a "end", even if there are local variables declared in the
Also, the manual could show one or two examples for typical "continue"
or "redo" usage, as it is not trivial.