Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Lua process control


May 12, 2021 Lua


Table of contents


Lua process control

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:

Lua 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.