July 2018
Beginner
202 pages
5h 42m
English
What happens when none of the if or elseif statements evaluate to true? No chunk of code is executed. But, you might want some chunk of code to execute when none of the if/elseif arguments are true. This is what the else statement does. It executes a chunk of code when none of the statements tested by the preceding if/elseif tests were true.
Syntactically, the else statement is just an else/end chunk. The else statement always comes last, as demonstrated by the following code:
print ("Enter your name")name = io.read()if #name <= 3 then print ("that's a short name, " .. name)elseif #name <= 6 then print (name .. " is an average length name")else print ("that's a long name, " .. name)end
There can be only one else statement, and it must ...