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 Tests→→Boolean 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 Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra

Longest path: 72 steps · 319 total prerequisite topics

Prerequisites (2)

Leads To (3)