==
OperatorThe ==
operator is the operator for comparing equivalent values.
val1 == val2
- if val1
is equivalent to val2
.
1 | local val 1 = 4 |
2 | local val 2 = 2 * 2 |
3 |
4 | if val 1 = = val 2 then |
5 | print ( 'Equivalent!' ) |
6 | end |
The above code would print Equivalent! because val1 is equivalent to val2.
~=
OperatorThe ~=
operator is the comparing non-equivalent values! The exact opposite of ==
.
val1 ~= val2
- if val1 is not equivalent to val2.
1 | local val 1 = 4 |
2 | local val 2 = 1 |
3 |
4 | if val 1 ~ = val 2 then |
5 | print ( 'Not Equivalent!' ) |
6 | end |
The above code would print Not Equivalent! because val1 is not equivalent to val2.
Both ==
and ~=
are used in if
or repeat - until
functions. ==
means 'is equal to', and ~=
means 'is NOT equal to'.
Example:
1 | if Value = = true then |
2 | --Code |
3 | elseif Value ~ = true then |
4 | --Other code |
5 | end |