How to write if statement in Lua with not equal symbol for boolean variable.
//In Java,
boolean a;
a = false;
if(!a){
//do something
}
-- In Lua I am trying to replicate the same code
local a
a = false
if(~a) then
-- do something
end
But I am getting error. How to write this in Lua ?
The operator == tests for equality; the operator ~= is the negation of equality. We can apply both operators to any two values. If the values have different types, Lua considers them different values.
The not operator is a unary operator and will return true if the operand is nil or false . Otherwise, it will return true .
The ~ operator means logical negation, and the ~= operator means not equals.
Lua uses mostly keywords. Use not a
instead of ~a
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With