2.6 Logical Operators

So far you’ve learned how to use relational operators to evaluate if some relation between two numbers is true or not. But what if you wanted to evaluate multiple conditions? Or some combination of conditions?

If you wanted to know if it were raining outside, you would check if some condition is true.

Fundamentally, even relational operators arrive at an answer by checking if certain conditions have been met based on some combination of one or more other true-false conditions.

This is a branch of mathematics called ‘Boolean Algebra.’ If that sounds intimidating, don’t be.

You’ve already met the Boolean data type earlier. Boolean, named after English mathematician and philosopher George Boole, deals in values that are only ever 1 or 0 (true or false).

And in Lua, we’re only interested in a subset of Boolean algebra and a subset of Boolean operators: ‘and‘, ‘or‘, and ‘not‘.