Control structures
Control structures are used to make decisions in code; they control the path of code based on a Boolean value. Lua provides the if
statement for this purpose. An if
statement is followed by a Boolean condition, which in turn is followed by a then
/end
chunk. The chunk is only executed when the Boolean condition evaluates to true.
The most basic syntax of an if statement is as follows:

if
A logical control structure always starts with an if statement. As described previously, an if
statement consists of the if
keyword, a Boolean expression, and a then
/end
chunk. The then/end chunk is only executed when the Boolean condition evaluates to true
. The following code sample demonstrates the basic use of an if statement:
print ("Enter your name") name = io.read() if #name <= 3 then print ("that's a short name, " .. name) end
elseif
You might want to make a more complicated decision than a simple if statement allows. For example, you may want to do one thing if the length of a...