Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Computational Thinking · Grade 6-8

Boolean Logic

Boolean logic is the system that works with only two values, true and false, combined using AND, OR, and NOT.


Quick Answer

Boolean logic is the system that works with only two values, true and false, combined using AND, OR, and NOT. Use it to build and evaluate conditions: (age >= 13) AND (hasPermission) is true only when both parts are true, (isWeekend) OR (isHoliday) is true when at least one is, and NOT flips a value. Every if statement, search filter, and digital circuit reduces its inputs to one true-or-false answer this way. Evaluate NOT first, then AND, then OR, unless brackets say otherwise.

Why This Matters

Boolean logic lets you write exact rules: free shipping if the total is over $50 OR the customer is a member; a ride that requires height >= 120 AND age >= 8. Mixing up AND and OR lets the wrong people in or keeps the right people out, and negating a condition incorrectly is one of the most common reasons an if statement does the opposite of what was intended.

Intuitive Explanation

Each simple condition is a question with a yes-or-no answer: is the temperature above 30? Is the door locked? Boolean logic combines the answers. A AND B is true only when both are true. A OR B is true when at least one is true, including when both are. NOT A is the opposite of A. Because each input has only two possible values, you can list every case: two inputs give just four combinations, and a truth table shows the result for each.

Take a theme-park ride with the rule height >= 120 AND age >= 8. For a 9-year-old who is 125 cm tall: true AND true gives true, so they may ride. For a 10-year-old who is 115 cm: false AND true gives false. Change AND to OR and the 115 cm child would be let on, which is why choosing the operator is a safety decision, not a detail.

Negation needs care. The opposite of 'tall enough AND old enough' is not 'not tall enough AND not old enough'; it is 'not tall enough OR not old enough', because failing either rule keeps you off. That is De Morgan's law: NOT (A AND B) = (NOT A) OR (NOT B). Notice also how this differs from Selection: boolean logic only works out a true-or-false value, and an if statement is what uses that value to choose which code runs.

Think of it like this. AND is like two switches in a row on one wire: the lamp lights only if both are on. OR is like two switches side by side on separate wires: either one alone lights the lamp. NOT is a push-button that cuts the power while it is pressed. The circuits inside computers are built from gates that work almost exactly this way.

Core idea. All program conditions ultimately reduce to a single true or false decision at each step.


When to Use

Use boolean logic when a condition joins simpler conditions with AND, OR, or NOT, or when you must evaluate a condition for given values, write its opposite, or fill in a truth table. Work inside brackets first, then NOT, then AND, then OR. If the question is which block of code runs as a result, add Selection; a single comparison such as x > 5 on its own needs no combining at all.

Tip. Ask: Do several true-or-false conditions have to be combined with AND, OR, or NOT into a single true or false result?

How to Recognize It

Before using Boolean logic, list each separate true-or-false condition and the words that join them.

  1. Are two or more conditions joined, like 'tall enough and over 10'?

    Yes means Boolean logic decides the overall answer. A single condition on its own is just one Boolean value.

  2. Must every condition be true, or is one enough?

    Every one means AND; at least one means OR. If a condition has to be flipped, as in 'not raining', add NOT.

  3. Are you asked for every possible combination of true and false inputs?

    Yes points to Truth Tables, which list all the combinations. Boolean logic on its own can work out just the case in front of you.

  4. Is the question about which code runs once the condition is known?

    Yes means Selection is doing the choosing; Boolean logic only produced the true or false that it uses.

Boolean Logic vs Boolean vs Logical Operators vs Truth Tables

The word Boolean appears in several of these names, which causes the mix-up. Ask whether you mean the rules for combining true and false, one true-or-false value, the symbols that combine them, or a full list of cases.

Boolean Logic

Meaning
Boolean logic is the set of rules for combining true and false values with AND, OR and NOT to get one result.
Key test
Several conditions are combined and reduced to one answer.
Formula
A∧B, A∨B, ¬A
Example
(NOT isRaining) AND isWeekend is true on a dry Saturday.

Boolean

Meaning
A Boolean is a data type that holds exactly one of two values, true or false.
Key test
One stored true or false, not a combination.
Example
gameOver = False stores a single Boolean value.

Logical Operators

Meaning
Logical operators are the symbols a language uses for AND, OR and NOT, such as and, or, not in Python, or && and || in JavaScript.
Key test
The question is about one operator's symbol and what it does.
Formula
T∧F=F
Example
In Python, not True gives False.

Truth Tables

Meaning
A truth table lists every combination of true and false inputs and the result for each one.
Key test
Every combination is listed: 2n rows for n inputs.
Formula
2n rows
Example
A OR B has 4 rows, and only the row with A false and B false gives false.

Formula & Notation

Worked Examples

Example 1 — Evaluate a combined condition

Easy

For age = 15, hasTicket = true, and isMember = false, evaluate (age >= 16 AND hasTicket) OR isMember. Then evaluate it again with isMember = true.
Show the steps and the answer
  1. Evaluate the comparison: 15 >= 16 is false.

    Comparisons become true or false before any AND or OR is applied.

  2. Evaluate the bracket: false AND true = false.

    AND needs both parts true, and the age part is false.

  3. Evaluate the whole condition: false OR false = false.

    OR needs at least one true part, and with isMember false there is none.

  4. With isMember = true: false OR true = true.

    One true part is enough for OR, so membership lets this 15-year-old in.

Answer: False when isMember is false; true when isMember is true.

Takeaway: Turn each comparison into true or false first, then apply the operators, brackets first.

Example 2 — Same values, different brackets

Standard

For A = true, B = true, and C = false, evaluate A OR B AND C, and then (A OR B) AND C.
Show the steps and the answer
  1. Apply precedence: AND is evaluated before OR, so A OR B AND C means A OR (B AND C).

    In most languages AND binds tighter than OR, much as multiplication comes before addition.

  2. B AND C = true AND false = false; then A OR false = true OR false = true.

    The OR is decided by A alone.

  3. With brackets: (A OR B) AND C = (true OR true) AND false = true AND false = false.

    The brackets force the OR to happen first, and the AND with a false C makes the whole thing false.

Answer: A OR B AND C is true; (A OR B) AND C is false.

Takeaway: AND is evaluated before OR; add brackets whenever you mean something else, or whenever a reader might be unsure.

Example 3 — Find the mistake: negating an AND

Application

A game should show 'Try again' unless the player has both a key and enough coins. Rin writes the 'Try again' condition as NOT hasKey AND NOT enoughCoins. Find the mistake and correct it, using a player with hasKey = true and enoughCoins = false.
Show the steps and the answer
  1. Write what 'Try again' should mean: NOT (hasKey AND enoughCoins).

    The player fails whenever the two items are not both present.

  2. Test Rin's version: NOT true AND NOT false = false AND true = false, so no 'Try again' appears.

    This player has no coins and should see 'Try again', so Rin's condition is wrong.

  3. Apply De Morgan's law: NOT (A AND B) = (NOT A) OR (NOT B), giving NOT hasKey OR NOT enoughCoins.

    Moving NOT inside the brackets flips AND into OR.

  4. Test the fix: false OR true = true, so 'Try again' appears.

    Missing either item is now enough to trigger the message.

Answer: Use NOT hasKey OR NOT enoughCoins (the same as NOT (hasKey AND enoughCoins)); this player now sees 'Try again'.

Takeaway: Negating an AND gives an OR of the negations, and negating an OR gives an AND.

Where You'll See It

  • A roller coaster's two rules

    You can ride only if you are tall enough AND healthy; AND means both must be true, so failing either one keeps you off the ride.

  • Getting a snack permission

    Mom says yes if you finished homework OR it's the weekend; OR means just one being true is enough to get the snack.

  • Filtering a video search

    Choosing 'cat videos AND under 5 minutes' narrows results to clips that satisfy both conditions, exactly how boolean AND combines filters.

Common Mistakes

  1. The slip: AND and OR mean basically the same 'combine two conditions' thing.

    Why it's tempting: Both join two true/false conditions, so they feel interchangeable.

    Instead: AND is true only when both parts are true (stricter); OR is true when at least one part is true (more permissive).

  2. The slip: NOT (A AND B) is the same as (NOT A) AND (NOT B).

    Why it's tempting: Pushing NOT inside and keeping AND looks like the natural move.

    Instead: By De Morgan's law, NOT (A AND B) = (NOT A) OR (NOT B): negating flips AND into OR (and OR into AND).

  3. The slip: Boolean operators all have the same precedence, so just read left to right.

    Why it's tempting: Reading left to right is how we read everything else.

    Instead: Precedence matters: NOT binds tightest, then AND, then OR; A OR B AND C means A OR (B AND C), so use parentheses when unsure.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. With `x = 7`, is `(x > 0) and (x < 10)` true or false?

    Hint: Check each part on its own first.

  2. Access is allowed if `password_ok and account_active`. The password is correct, but the account is suspended. Is access allowed?

    Hint: What is `account_active` here?

  3. With `age = 15` and `has_ticket = False`, evaluate `age >= 13 or has_ticket`, then `age >= 13 and has_ticket`.

    Hint: Work out `age >= 13` first, then apply each operator.

  4. With `a = True`, `b = False` and `c = True`, evaluate `not a or b and c`.

    Hint: NOT is done first, then AND, then OR.

  5. You must list the result of `A or B` for all four combinations of A and B. Should you evaluate one expression, or build a truth table?

    Hint: How many input combinations do you need to cover?

  6. A student rewrites `not (rainy and cold)` as `not rainy and not cold`. Test both with `rainy = True` and `cold = False`. Are they the same?

    Hint: Evaluate the original and the rewrite separately, then compare.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why is it called Boolean?

It is named after George Boole, an English mathematician who in 1854 published a book showing that logic could be written and worked out like algebra, using only true and false. More than 80 years later, Claude Shannon showed that Boole's rules matched circuits made of electrical switches, and that idea became the basis for designing computer chips.

Does OR in code mean the same as 'or' in everyday speech?

Not always. In everyday speech, 'you can have cake or ice cream' usually means one but not both. In Boolean logic, A OR B is also true when both are true. The one-but-not-both meaning has its own name, exclusive or, written XOR. Two light switches for one staircase light behave like XOR: flipping either switch always changes the light.

Why can a program skip the second half of an AND?

If the first part of A AND B is false, the whole thing must be false whatever B is, so most languages never check B. This is called short-circuit evaluation, and OR does the same when its first part is true. Programmers use it on purpose: (count > 0) AND (total / count > 10) never divides by zero, because the division is skipped when count is 0.

Learning Path

← Before

Selection
Boolean Logic

You are here

You need Selection: an if statement runs a block when its condition is true. Boolean logic shows how to build those conditions from smaller true-or-false pieces with AND, OR, and NOT, and how to negate them correctly. Next, Truth Tables list every combination of inputs with its result, and Logical Operators look at how AND, OR, and NOT are written and evaluated in real programming languages.

See Also