- Lua Quick Start Guide
- Gabor Szauer
- 120字
- 2021-08-05 10:30:43
Nesting if statements
if/elseif/else statements control the execution of chunks of code. Like chunks, if statements can be nested. The same rule for scope applies to nested if statements as it does to nested chunks. The following code demonstrates the use of nested if statements:
print ("Enter a number")
x = io.read()
if x == "6" then
print ("x is six!")
print ("Enter another number")
local y = io.read()
-- Nested if statement begins here
if y == "6" then
print ("y is also six!")
elseif y == "5" then
print ("y is one less than x")
else
print ("x is 6, but y is not!")
end
-- Nested if statement ends here
else
print ("x is not 6!" .. x)
end
推薦閱讀
- Visual C++程序設計學習筆記
- Building a RESTful Web Service with Spring
- 機器人Python青少年編程開發實例
- C#程序設計教程
- Java:Data Science Made Easy
- Python貝葉斯分析(第2版)
- C語言課程設計
- 高級語言程序設計(C語言版):基于計算思維能力培養
- 量化金融R語言高級教程
- Windows內核編程
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- Java零基礎實戰
- Scala編程實戰
- AMP:Building Accelerated Mobile Pages
- The Statistics and Calculus with Python Workshop