Why does Lua have no “continue” statement?

后端 未结 11 1685
无人及你
无人及你 2020-12-07 13:23

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
11条回答
  •  -上瘾入骨i
    2020-12-07 13:58

    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

提交回复
热议问题