11

How do I write an if statement in Lua that negates (inverts/flips) a Boolean variable used as the condition?

For example, in Java, one can write:

boolean a;
a = false;
if (!a) {
    //do something
}

I tried to replicate the above Java code in Lua using the following:

local a
a = false
if (~a) then
    -- do something
end

However, I received an error. How do I write the Lua equivalent of the above Java snippet?

Kyle F Hartzenberg
  • 2,567
  • 3
  • 6
  • 24
Venkatesh
  • 3,558
  • 8
  • 32
  • 38

1 Answers1

22

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

lhf
  • 70,581
  • 9
  • 108
  • 149