Lua flow control

Lua programming language flow control statements are set by program setting one or more conditional statements. Execute specified program code when the condition is true, and execute other specified code when the condition is false.

The following is a typical process control flow chart:


The conditional expression result of the control structure can be any value. Lua considers false and nil to be false, and true and non-nil to be true. .

It should be noted that 0 in Lua is true:

--[ 0 为 true ]
    print("0 为 true")

The output result of the above code is:

0 为 true

Lua provides the following control structure statements:

if statementif statement consists of a Boolean expression As a conditional judgment, it is followed by other statements.
if...else statement if statement can be used in conjunction with else statement , in the if conditional expression When it is false, the else statement code is executed.
if Nested StatementsYou can use one or more inside if or else if if or else if statement.