Lua为什么没有“继续"?陈述? [英] Why does Lua have no "continue" statement?

查看:16
本文介绍了Lua为什么没有“继续"?陈述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

推荐答案

在 Lua 5.2 中最好的解决方法是使用 goto:

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

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

This is supported in LuaJIT since version 2.0.1

这篇关于Lua为什么没有“继续"?陈述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆