Lua 用于范围内的变量 [英] Lua For Variable In Range
本文介绍了Lua 用于范围内的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法让它发挥作用.我来自 Python,所以我尝试对它使用相同的语法,但不出所料,它不起作用:
I can't seem to get this to work. I come from Python, so I tried using the same syntax for the hell of it, but it unsurprisingly wouldn't work:
var = 4
for var in range(2,20) do
print ("var is in range")
end
推荐答案
如果你想测试一个值是否在一个范围内,使用
If you want to test whether a value is in a range, use
if var>=2 and var<=20 then
print ("var is in range")
end
如果你想要一个循环,使用
If you want a loop, use
for var=2,20 do
print(var)
end
这篇关于Lua 用于范围内的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文