Lua流程控制

作者:追风剑情 发布于:2022-4-26 10:26 分类:Lua

if 语句

x = 1
if x==1 then
	print("1")
elseif x==2 then
	print(2)
else
	print("other")
end

while 语句

x = 1
while (x < 5) do
	print("while循环")
	x = x+1
end

for 语句

-- 数值for循环
for i=1, 10, 2 do
	print("i="..i)
end

-- 泛型for循环,类似C#或java中的foreach
a = {"one", "two", "three"}
for i, v in ipairs(a) do
	print(i, v)
end

repeat until 语句

x = 1
repeat
	print(x)
	x = x + 1
until(x > 5) --当条件为真是退出循环

标签: Lua

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号