lua学习笔记5(分支结构和循环的学习)

Lua 复制代码
print("*****************分支结构和循环的学习******************")
print("*****************if else语句******************")
--if 条件 then end
a=660
b=670
--单分支
if a<b then
	print(a)
end
--双分支
if a>b then
	print("满足条件")
else
	print("不满足条件")
end
--多分支
if a>b then
	print("满足条件")
elseif a==668 then --elseif必须要连着写不然会报错后面还要加then
	print("还差一点满足")
elseif a==666 then
	print("终于满足了")
else--最后一个else不用加then
	print("放弃了不找了")
end
print("*****************while do语句******************")
num=10
while num<20 do
	print(num)
	num=num+1
end
print("*****************do while语句******************")
num=1145;
repeat
	print(num)
	num=num+1
until num>1148--满足条件就退出
print("*****************for语句******************")
for i=8848,8850 do--默认递增+1,直到满足大于后面的那个数
	print(i)
end
for i=666,671,2 do--自定义增量就在后面加一个数
	print(i)
end
for i=671,666,-2 do--自定义增量就在后面加一个数,这个数可以是负数
	print(i)
end
print("*****************lua中没有switch语句******************")

输出

相关推荐
minglie15 小时前
高等代数试题
学习
Xiaofeng36936 小时前
GPT-5.6 发布后,我用了一个周末重新规划学习路线图
gpt·学习
其实防守也摸鱼7 小时前
运维--怎么看接口的请求和返回
运维·学习·网络安全·网络攻击模型·burpsuite·攻防对抗·蓝队
酷讯网络_2408701607 小时前
区块粮仓宠物NFT源码区块狗/抢购转让预约区块投资理财系统
学习·开源·宠物
疯狂打码的少年7 小时前
【软件工程】软件开发模型:增量模型与迭代模型
笔记·软件工程
Generalzy8 小时前
从本地 Demo 到生产级检索:Milvus 学习笔记(3)
笔记·学习·milvus
心中有国也有家9 小时前
AtomGit Flutter 鸿蒙客户端:ModalBottomSheet 实战
android·javascript·学习·flutter·华为·harmonyos
tyqtyq229 小时前
求职信生成:AI 智能求职信撰写系统的鸿蒙实现
人工智能·学习·华为·生活·harmonyos
MartinYeung59 小时前
[论文学习]PrivacyLens:评估语言模型在行动中的隐私规范意识
人工智能·学习·语言模型
凉、介10 小时前
Virtio 系列(一):框架概览
笔记·学习·嵌入式·虚拟化·virtio