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

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
主站蜘蛛池模板: 金沙县| 奈曼旗| 郑州市| 文水县| 霞浦县| 永登县| 绍兴市| 法库县| 辽中县| 云南省| 乐至县| 肥西县| 南昌县| 鄂托克前旗| 芦山县| 京山县| 金湖县| 桦川县| 徐水县| 同仁县| 绥德县| 若羌县| 金塔县| 澄江县| 淮阳县| 随州市| 美姑县| 青阳县| 富裕县| 隆尧县| 玉田县| 英吉沙县| 安化县| 阿拉善右旗| 乃东县| 如皋市| 新余市| 綦江县| 渭源县| 砀山县| 连江县|