Simple If Statements

this may be quite nooby a question so prepare but, what does

if (c) then -- do something end

mean and what does

if not c then -- do something end

mean?

-- True if c then -- same as: if c == true if (c) then -- same as: if c == true -- False OR nil if not c then -- same as: if (c == nil or c == false) then if not (c) then -- ditto

brackets can be used to make things clearer, and they have a place when you need to be strict about the order of mathematical execution, but in general Lua works just fine without them.

exactly as richard9 said, adding only the reverse case:

if (c==false) then – c is NOT nil, c evaluates to a boolean value false

that is, “c==false” is not strictly equivalent to “not c”, and this can bite you if nils are present

-- True if c then -- same as: if c == true if (c) then -- same as: if c == true -- False OR nil if not c then -- same as: if (c == nil or c == false) then if not (c) then -- ditto

brackets can be used to make things clearer, and they have a place when you need to be strict about the order of mathematical execution, but in general Lua works just fine without them.

exactly as richard9 said, adding only the reverse case:

if (c==false) then – c is NOT nil, c evaluates to a boolean value false

that is, “c==false” is not strictly equivalent to “not c”, and this can bite you if nils are present