Logical Operators

The conjunction operator and returns nil if its first argument is nil; otherwise, it returns its second argument.The disjunction operator or returns its first argument if it is different from nil; otherwise, it returns its second argument. Both and and or use short-cut evaluation, that is, the second operand is evaluated only if necessary.

Two useful Lua idioms that use logical operators are (where b should not be nil):

x = x or v        <->  if x == nil then x = v end
x = a and b or c  <->  if a then x = b else x = c end