加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua初识(4)_判断语句

发布时间:2020-12-14 21:55:27 所属栏目:大数据 来源:网络整理
导读:lua中的判读语句三个关键字 if,else, elseif, end判读语句的三种格式:一、、if 表达式 then 语句块 end 二、if 表达式 then语句块1else 语句块2end三、只能有一个if和elseif 表达式1 then 语句块1elseif 表达式2 then语句块2elseif 表达式3 then语句块3。
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




	
	
	
	
	
	
	
	
	
	

 
 
 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读