Lua Logical Operators

Lua supports common logical operators and, or and not. In logical operations, nil is regarded as false, and values ​​other than boolean false and nil are regarded as true. If the first operand is false, the result of the and operation is The first operand, otherwise the second operand; if the first operand is not false, the result of the or operation is the first operand, otherwise the result is the second operand.

> 4 and 5 --> 5

> nil and 13 --> nil

> false and 13 --> false

> 0 or 5 --> 0

> false or "hi" --> "hi"

> nil or false --> false


priority:

And operator has higher precedence than Or. For example: ((a and b) or c) is equivalent to (a and b or c)

Guess you like

Origin blog.csdn.net/leon_founder/article/details/78256924