Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean Not Equal To in Lua programming

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 ?

like image 487
Venkatesh Avatar asked Feb 26 '14 00:02

Venkatesh


People also ask

How do you write not equal to 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.

What is the NOT operator in Lua?

The not operator is a unary operator and will return true if the operand is nil or false . Otherwise, it will return true .

Does ~= mean not equal?

The ~ operator means logical negation, and the ~= operator means not equals.


1 Answers

Lua uses mostly keywords. Use not a instead of ~a.

like image 148
lhf Avatar answered Sep 27 '22 15:09

lhf