This article mainly introduces the use of the IF statement in Lua, is the basic knowledge in Lua's introductory study, and needs friends to refer to the following
An If statement consists of one or more statements consisting of a Boolean expression.
Grammar
The IF statement syntax for the LUA programming language is:
The code is as follows:
if (boolean_expression)
Then
--[statement (s) would execute if the Boolean expression is true--]
End
If the Boolean expression evaluates to the code if the IF statement is true, the block is executed. If the end of the IF statement (after the closing brace) evaluates to False, the first set of code is executed.
The LUA programming language assumes a value of false if any combination of Boolean true and non-0 values is true and whether it is Boolean false or 0. It should be noted, however, that the LUA 0 values are also considered true.
Example:
The code is as follows:
--[local variable definition--]
A = 10;
--[Check the Boolean condition using if statement--]
if (a < 20)
Then
--[if condition is true then print the following--]
Print ("A is less than 20");
End
Print ("Value of A is:", a);
When the above code is built and run, it produces the following results.
The code is as follows:
A is less than 20
Value of a is:10