Logical Operators
Logical operators combine Boolean values and expressions (true/false), making them very useful for decisions.
| MATH | C# | Operation | Description |
|---|---|---|---|
| ⋀ | && | AND | True when all elements are true. |
| ⋁ | || | OR | True when at least one element is true. |
| ¬ | ! | NOT | The inverse of an element. |
This can be visually understood with some cute venn diagrams:

Operator and
Both operands must be True for the result to be True.
| English | C# |
|---|---|
| The relative humidity index must be below 100% AND the temperature has to be decreasing for it to rain | humidity_index < 100 && temperature_variation < 0 |
Operator or
At least one operand must be True for the result to be True.
| English | C# |
|---|---|
| The oil in the car should be changed every 6 months OR every 5,000 km: | num_months >= 6 || mileage >= 5000 |
Operator not
Negates a single operand, unlike and/or, which each take two.
| English | C# |
|---|---|
| I can borrow a book if I do NOT have an overdue book. | is_permissible = !has_overdue_books |
References
Bultena, Sandra and Youmna Badawy. "Integers & Floats." 420-SN1 Notes, John Abbott College, john-abbott-college.github.io/SN1-Notes/topics/04_variables/03_integers_floats/03_integers_floats.html
Buschinelli, Mauricio. "420-1P6 - Week 5" John Abbott College, Fall 2023.