Usage of logical operators in Lua
This article describes how to use logical operators in Lua. It is the basic knowledge of Lua beginners. For more information, see
The following table lists all logical operators supported by Lua. Assume that variable A holds true, and variable B holds false:
Example
Try the following example to understand the logical operators provided by all Lua programming languages:
The Code is as follows:
A = 5
B = 20
If (a and B)
Then
Print ("Line 1-Condition is true ")
End
If (a or B)
Then
Print ("Line 2-Condition is true ")
End
-- Lets change the value ofa and B
A = 0
B = 10
If (a and B)
Then
Print ("Line 3-Condition is true ")
Else
Print ("Line 3-Condition is not true ")
End
If (not (a and B ))
Then
Print ("Line 4-Condition is true ")
Else
Print ("Line 3-Condition is not true ")
End
When the above program is established and executed, it will produce the following results:
The Code is as follows:
Line 1-Condition is true
Line 2-Condition is true
Line 3-Condition is true
Line 3-Condition is not true