Why does Lua have no "continue" statement?

Dant picture Dant · Aug 19, 2010 · Viewed 123k times · Source

I have been dealing a lot with Lua in the past few months, and I really like most of the features but I'm still missing something among those:

  • Why is there no continue?
  • What workarounds are there for it?

Answer

catwell picture catwell · Oct 17, 2012

In Lua 5.2 the best workaround is to use goto:

-- prints odd numbers in [|1,10|]
for i=1,10 do
  if i % 2 == 0 then goto continue end
  print(i)
  ::continue::
end

This is supported in LuaJIT since version 2.0.1