Lua顺序执行循环

1.一般赋值语句

local aa=1;
aa ="HELLOW WORLD"
aa ={
  bb = 1,
  [1] =2,
}

2.字符串的加减法(使用…而不是+)

local bb = "hellow"
bb =bb .."world"
print(bb)
-- Lua没有简化表达式
--[[
temp = 1
temp += 3
temp ++
]]
-- end

3.if判断语句

local temp =2
if temp > 1 then
print("符合条件"..temp)
end

if true and true then 
	print("true and true")
end
-- if elseif 
temp = 35
if temp > 50 then
	print("temp > 50")
elseif temp > 30 then 
	print("temp (30, 50]")
elseif temp > 10 then
	print("temp (10, 30]")
end 

4.for循环语句

-for循环语句, 
--for 初始值, 结束值, 每次迭代的步长(可写可不写) do end
-- 从1打印到10
local i = 1
--包括了结束值
for i = 1, 10 do -- 默认步长为1
	print(i)
end 

for i = 1, 10, 2 do 
	print(i)
end

for i = 10, 1, -1 do 
	print(i)
end

5.while循环语句

-- while循环
i = 1
sum = 0
while i <= 100 do --只要条件为真就会执行while
	sum = sum + i
	i = i + 1
end
print(sum)
-- end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值