May 12, 2021 Lua
The Lua programming language process control statement is set by the program setting one or more conditional statements. The specified program code is executed when the condition is true and other specified code is executed when the condition is false.
Here is a typical flowchart of process control:
The conditional expression result that controls the structure can be any value, and Lua considers false and nil, true and non-nil true.
Note that 0 in Lua is true:
--[ 0 为true ] if(0) then print("0 为真") end
The above code output is:
0 为真
Lua provides the following control structure statements:
Statement | Describe |
---|---|
The if statement | If statements are judged by a Boolean expression as a condition, followed by other statements. |
if... Else statement | The if statement can be used in combination 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 in an if or else if. |