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 ] if(0) then print("0 为 true") end
The output result of the above code is:
0 为 true
Lua provides the following control structure statements:
Statement | Description |
---|---|
if statement | if 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 Statements | You can use one or more inside if or else if if or else if statement. |