Lua初识(4)_判断语句

lua中的判读语句
三个关键字 if, else, elseif, end

判读语句的三种格式:

一、、
if 表达式 then
 语句块
 end
 
二、
if 表达式 then
	语句块1
	else
   语句块2
end

三、只能有一个if和else
if 表达式1 then
  语句块1
elseif 表达式2 then
语句块2
elseif 表达式3 then
语句块3
。。。
else
	语句块N
end

For example One:

function ceshi(num)
	if(num == "hello") then
		print("hello")
	else
		print("num:"__num)
	end
end
a = "lala"
ceshi(a)

For example Two:

local today = 1
if today == 1 then
	print(“Today is Monday!”)
elseif today == 2 then
	print(“Today is Tuesday!”)
elseif today == 3 then
	print(“Today is Wednesday!”)
elseif today == 4 then
	print(“Today is Thursday!”)
elseif today == 5 then
	print(“Today is Saturday!”)
elseif today == 6 or today == 7 then
	print(“Rest!”)
else
	print(“None!”)
end



local cj = 99;
if cj <= 100 and cj >= 90 then
<span style="white-space:pre">	</span>print("优秀")
elseif cj < 90 and cj > 70 then
<span style="white-space:pre">	</span>print("良好")
elseif cj <= 70 and cj >= 60 then
<span style="white-space:pre">	</span>print("及格")
elseif cj < 60 and cj >= 0 then
<span style="white-space:pre">	</span>print("不及格")
else
<span style="white-space:pre">	</span>print("您的成绩有误!")
end
<span style="white-space:pre">	</span>
local a = 8888;
if a % 2 == 0 and a > 100 then
<span style="white-space:pre">	</span>print("a是个大于100 的偶数!")
else
<span style="white-space:pre">	</span>print("a不是一个大于100的偶数!") 
end<span style="font-family: Arial, Helvetica, sans-serif;">	</span>


local a, b = 110, 130
if a % 2 == 1 and a <= 200 and b % 2 == 1 and b <= 20 then
print("a和b都是小鱼等于200的奇数")
elseif a % 2 == 1 and a <= 200 then 
print("只有a是小于等于200的奇数")
elseif b % 2 == 1 and b <= 200 then
print("只有b是小于等于200的奇数")
else
print("a和b都不是小于等于200的奇数")
end












  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值