July 2018
Beginner
202 pages
5h 42m
English
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 hereelse print ("x is not 6!" .. x)end