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

查看:96
本文介绍了为什么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

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

This is supported in LuaJIT since version 2.0.1

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

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