官术网_书友最值得收藏!

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
主站蜘蛛池模板: 沙雅县| 肃北| 忻城县| 南汇区| 延边| 白河县| 临沭县| 彰化县| 岳西县| 陇西县| 逊克县| 沐川县| 苏州市| 德钦县| 固安县| 汝南县| 左权县| 封丘县| 古浪县| 伊金霍洛旗| 广河县| 景东| 包头市| 五大连池市| 纳雍县| 德庆县| 江川县| 洪雅县| 客服| 舟山市| 尼玛县| 资阳市| 株洲市| 驻马店市| 鄢陵县| 和林格尔县| 凉山| 曲麻莱县| 得荣县| 正镶白旗| 蓝山县|