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:
Copy Code code 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:
Copy Code code 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.
Copy Code code as follows:
A is less than 20
Value of a is:10