Boolean Operators

Booleans Operators

You can also connect boolean expressions together using the && (AND) and the || (OR) operator. For example, suppose I ask: “Are you a human, and is Nuvi a robot?” The word “and” connects the two true-false questions together. In this case, since it is true that you are a human, and it is also true that Nuvi is a robot, then the overall result is true.

Here’s a chart that describes what happens when we connect booleans together:

ExpressionResultExpressionResult
true && truetruetrue || truetrue
true && falsefalsetrue || falsetrue
false && truefalsefalse || truetrue
false && falsefalsefalse || falsefalse

To summarize, && requires both Boolean expressions to be true, while || only requires one of the two Boolean expressions to be true. Here are some more examples:

alt text height=

Working Together

Try guessing the answers to the following expressions. Use Console.WriteLine to print out the answers.

  • (9 < 10) && (12 => 11)
  • (15 - 2 == 11) || (4 % 3 != 2)