- 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
推薦閱讀
- Oracle從入門到精通(第3版)
- Java Web開發之道
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- 手把手教你學C語言
- Learning Unity 2D Game Development by Example
- jQuery炫酷應用實例集錦
- 深度學習原理與PyTorch實戰(第2版)
- Julia數據科學應用
- PhoneGap 4 Mobile Application Development Cookbook
- Arduino機器人系統設計及開發
- TypeScript圖形渲染實戰:2D架構設計與實現
- C語言程序設計與應用實驗指導書(第2版)
- C# 10核心技術指南
- Practical Time Series Analysis
- C++標準庫(第2版)