How to Use Relational operators in Lua
This article describes how to use Relational operators in Lua. It is the basic knowledge in Lua learning. For more information, see
The following table lists all Relational operators supported by Lua. Assume that variable A holds 10 and variable B holds 20:
Example
Try the following example to understand the Relational operators provided by all Lua programming languages:
The Code is as follows:
A = 21
B = 10
If (a = B)
Then
Print ("Line 1-a is equal to B ")
Else
Print ("Line 1-a is not equal to B ")
End
If (~ = B)
Then
Print ("Line 2-a is not equal to B ")
Else
Print ("Line 2-a is equal to B ")
End
If (a <B)
Then
Print ("Line 3-a is less than B ")
Else
Print ("Line 3-a is not less than B ")
End
If (a> B)
Then
Print ("Line 4-a is greater than B ")
Else
Print ("Line 5-a is not greater than B ")
End
-- Lets change value of a and B
A = 5
B = 20
If (a <= B)
Then
Print ("Line 5-a is either less than or equal to B ")
End
If (B> =)
Then
Print ("Line 6-B is either greater than or equal to B ")
End
When the above program is established and executed, it will produce the following results:
The Code is as follows:
Line 1-a is not equal to B
Line 2-a is not equal to B
Line 3-a is not less than B
Line 4-a is greater than B
Line 5-a is either less than or equal to B
Line 6-B is either greater than or equal to B