Lua中的循环,分为while 循环、for循环和 repeat...until 循环,语法比较简单,看看例子就秒懂了。
while循环
-- while 循环
--[[
while(condition)
do
statement
end
--]]
local a = 0
while(a < 1000 )
do
a = a +1
print(a)
end
for循环
--[[
Lua 编程语言中数值 for 循环语法格式:
for var=exp1,exp2,exp3 do
<执行体>
end
var 从 exp1 变化到 exp2,每次变化以 exp3 为步长递增 var,并执行一次 "执行体"。exp3 是可选的,如果不指定,默认为1。
--]]
for i=1,10,2 do
print("i:",i)
end
repeat ... until 循环
--[[
Lua 编程语言中 repeat...until 循环语法格式:
repeat
statements
until( condition )
-]]
b = 1000;
repeat
b = b -50
print(b)
until(b <0)