4.16.1. If…else statement #
Lua
if
statement allows nesting, which means that you can use a
if
or
else
if
statement to insert other
if
or
else
if
statement.
4.16.2. The syntax format of Lua if nested statements is as follows: #
if(Boolean expression 1)
then
--[Execute the statement block when Boolean expression 1 is true--]
if(Boolean expression 2)
then
--[Execute the statement block when Boolean expression 2 is true--]
end
end
You can nest in the same way
else
statement.
4.16.3. Example #
The following example is used to determine a variable The execution result of the above code is as follows:
a
and
b
Value:Example #
--[Define variables--]
a = 100;
b = 200;
--[Check Condition--]
if( a == 100 )
then
--[Perform the following if condition judgment when the if condition is true--]
if( b == 200 )
then
--[Execute the statement block when the if condition is true--]
print("The value of a is 100, and the value of b is 200" );
end
end
print("The value of a is:", a );
print("The value of b is:", b );
The value of a is 100, and the value of b is 200
The value of a is: 100
The value of b is: 200