A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Logical Operators and Boolean Algebra

College Depth 71 in the knowledge graph I know this Set as goal
969topics build on this
319prerequisites beneath it
See this on the map →
Boolean Type and Truth ValuesComparison Operators and Boolean TestsBoolean Algebra and Fundamental LawsConditional Statements+1 more
operators logic boolean

Core Idea

Logical operators (AND, OR, NOT) combine boolean values. AND requires both operands true; OR requires at least one true; NOT negates. Short-circuit evaluation optimizes by not evaluating unnecessary sub-expressions.

How It's Best Learned

Build truth tables for logical expressions. Test short-circuit behavior with side effects.

Common Misconceptions

Explainer

From boolean types and comparison operators, you know that expressions like `x > 5` and `name == "Alice"` evaluate to `True` or `False`. But real-world conditions are rarely that simple. "Is the user logged in *and* is their subscription active?" "Is the input empty *or* does it contain invalid characters?" Logical operators — `AND`, `OR`, and `NOT` — let you combine multiple boolean values into a single compound condition, giving you the power to express complex decision rules in one line.

AND requires *both* operands to be true for the result to be true. `is_logged_in AND has_permission` is true only when both conditions hold — if either is false, the whole expression is false. OR requires *at least one* operand to be true. `is_admin OR is_owner` is true if either condition holds, and only false when both are false. NOT inverts a single boolean: `NOT is_locked` is true when `is_locked` is false. A useful way to internalize these rules is to build a truth table — a grid that lists every combination of inputs and the resulting output. For AND with two inputs, there are four rows (TT, TF, FT, FF), and only the first row produces true. For OR, only the last row (FF) produces false.

Most programming languages implement short-circuit evaluation, which is both an optimization and a feature you can exploit. With AND, if the first operand is false, the result *must* be false regardless of the second operand, so the second operand is never evaluated. With OR, if the first operand is true, the result *must* be true, so the second operand is skipped. This matters when the second operand has a side effect or could cause an error. The classic pattern is `if list is not empty AND list[0] == target:` — short-circuit evaluation ensures that `list[0]` is only accessed when the list is non-empty, preventing an index error.

When combining multiple logical operators, precedence determines the order of evaluation: NOT binds tightest, then AND, then OR. The expression `a OR b AND c` is evaluated as `a OR (b AND c)`, not `(a OR b) AND c`. This parallels arithmetic, where multiplication binds tighter than addition. When in doubt, use parentheses to make your intent explicit — `(a OR b) AND c` leaves no ambiguity. De Morgan's laws provide useful equivalences for simplifying or rewriting compound conditions: `NOT (a AND b)` equals `(NOT a) OR (NOT b)`, and `NOT (a OR b)` equals `(NOT a) AND (NOT b)`. These laws are especially helpful when you need to negate a complex condition and want to distribute the NOT across each part.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean Algebra

Longest path: 72 steps · 319 total prerequisite topics

Prerequisites (2)

Leads To (3)