The result of the conditional expression of the control structure can be any value, and Lua considers false and nil to be false, and true and non-nil to be true.
Note that 0 is true in Lua:
--[ 0 为 true ]
if(0)
then
print("0 为 true")
end
The output of the above code is:
0 为 true
Lua provides the following control structure statements:
An if statement
consists of a Boolean expression as a conditional statement followed by other statements.
The if…else statement
can be used in conjunction with the else statement to execute the else statement code when the if conditional expression is false.
if Nested Statements
You can use one or more if or else if statements within an if or else if.