gpt4 book ai didi

loops - 为什么Lua没有 "continue"语句?

转载 作者:行者123 更新时间:2023-12-03 04:26:53 25 4
gpt4 key购买 nike

在过去的几个月里,我一直在与 Lua 打交道,我真的很喜欢其中的大部分功能,但我仍然缺少其中的一些功能:

  • 为什么没有继续
  • 有哪些解决方法?

最佳答案

在 Lua 5.2 及更高版本中,最好的解决方法是使用 goto:

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

LuaJIT 从 2.0.1 版本开始支持此功能

关于loops - 为什么Lua没有 "continue"语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3524970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com