if elseif的使用

来源:互联网 发布:西安聚航网络 编辑:程序博客网 时间:2024/06/09 20:19
local score = 95


print('------ if结构示例-------')
if score >= 85 then
  print("您真优秀!")
end


if score < 60 then
  print("您需要加倍努力!")
end


if score >= 60 and score < 85 then
  print("您的成绩还可以,仍需继续努力!")
end


print('------ if-else结构示例------')
if score < 60 then
  print("不及格")
else
  print("及格")
end


print('------elseif结构示例------')


local testscore = 76
local grade


if testscore >= 90 then
  grade = 'A'
elseif testscore >= 80 then
  grade = 'B'
elseif testscore >= 70 then
  grade = 'C'
elseif testscore >= 60 then
  grade = 'D'
else
  grade = 'F'
end
print("Grade = " .. grade)