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