Skip to main content

Logical Operators

Logical operators combine Boolean values and expressions (true/false), making them very useful for decisions.

MATHC#OperationDescription
⋀&&ANDTrue when all elements are true.
⋁||ORTrue when at least one element is true.
¬!NOTThe inverse of an element.

This can be visually understood with some cute venn diagrams:

and-or-not

Operator and

Both operands must be True for the result to be True.

EnglishC#
The relative humidity index must be below 100% AND the temperature has to be decreasing for it to rainhumidity_index < 100 && temperature_variation < 0

Operator or

At least one operand must be True for the result to be True.

EnglishC#
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.

EnglishC#
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.