Boolean Logic Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Boolean Logic.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

A system of logic that works with only two possible values—true and false—combined using the operators AND, OR, and NOT. Boolean logic provides the mathematical foundation for all decision-making in computing, from simple if-statements to complex database queries and digital circuit design.

Yes/no thinking. You combine simple true/false conditions into complex decisions with AND, OR, NOT.

Read the full concept explanation →

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

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

Common stuck point: AND requires both true. OR requires at least one true. NOT flips the value.

Sense of Study hint: When building complex boolean expressions, break them into small parts and evaluate each part separately first. Then combine them with AND/OR/NOT. Use truth tables if you are unsure—list every possible combination of inputs and work out the result for each.

Worked Examples

Example 1

medium
Evaluate: (TRUE AND FALSE) OR (NOT FALSE).

Answer

TRUE

First step

1
Step 1: TRUE AND FALSE = FALSE.

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Unlock answer keys One Family plan — every worked solution, all subjects

Example 2

medium
Complete the truth table for A AND (NOT B) where A and B can each be TRUE or FALSE.

Example 3

easy
Fill in the missing rows of A OR B: (T,T)→?, (T,F)→?, (F,T)→?, (F,F)→?.

Example 4

medium
Trace the access condition: allow = (isMember AND NOT banned) OR isAdmin. For isMember=TRUE, banned=TRUE, isAdmin=FALSE, does access succeed?

Example 5

medium
Show that A OR (A AND B) simplifies to A by checking all four (A,B) rows.

Example 6

hard
A condition is: ((NOT a) OR b) AND (a OR (NOT b)). Show this equals 'a == b' by evaluating all 4 rows.

Example 7

hard
A login form passes if (passwordOK AND NOT lockedOut) OR (recoveryCodeOK AND emailVerified). For passwordOK=F, lockedOut=F, recoveryCodeOK=T, emailVerified=F, does the user log in?

Example 8

challenge
Prove using a truth table that (A AND B) OR (NOT A AND NOT B) is equivalent to NOT (A XOR B).

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
Evaluate: NOT (TRUE OR FALSE) AND TRUE.

Example 2

medium
Evaluate the condition `(loggedIn AND NOT suspended) OR teacherOverride` when loggedIn = TRUE, suspended = TRUE, and teacherOverride = FALSE.

Example 3

easy
Evaluate: true AND false.

Example 4

easy
Evaluate: true OR false.

Example 5

easy
Evaluate: NOT true.

Example 6

easy
Evaluate: false OR false.

Example 7

easy
Evaluate: true AND true.

Example 8

easy
Evaluate: NOT false.

Example 9

easy
Evaluate: true XOR true (XOR is true only when operands differ).

Example 10

easy
How many rows does a truth table for 2 boolean variables have?

Example 11

medium
Evaluate: (true AND false) OR true.

Example 12

medium
Apply De Morgan: rewrite NOT (A AND B) without the outer NOT.

Example 13

medium
Evaluate with precedence (NOT before AND before OR): NOT true AND false OR true.

Example 14

medium
Short-circuit: in 'false AND f(x)', is f(x) evaluated? Explain the result.

Example 15

medium
Evaluate: (5 > 3) AND (2 > 4).

Example 16

medium
Evaluate: NOT (false OR true).

Example 17

medium
A condition is 'A OR (B AND C)' with A=false, B=true, C=false. Evaluate.

Example 18

medium
Evaluate: (true OR false) AND (NOT false).

Example 19

medium
For how many of the 4 rows of (A OR B) is the result true?

Example 20

challenge
Build the truth table value: for how many of the 4 rows of (A AND B) is the result true?

Example 21

challenge
Simplify using De Morgan and double negation: NOT(NOT A OR NOT B).

Example 22

challenge
A guard is 'if NOT (age >= 18 AND hasID)'. For age=20, hasID=false, does the guard's body run? Show the logic.

Example 23

easy
Evaluate: FALSE OR TRUE.

Example 24

easy
Evaluate: TRUE AND TRUE AND FALSE.

Example 25

easy
Evaluate: NOT (TRUE AND TRUE).

Example 26

easy
Evaluate: NOT FALSE AND FALSE (use precedence: NOT first).

Example 27

medium
Evaluate: (NOT TRUE) OR (FALSE AND TRUE).

Example 28

medium
For variables A, B, C the expression is A AND (B OR C). With A=TRUE, B=FALSE, C=TRUE, evaluate.

Example 29

medium
Evaluate using precedence: TRUE OR FALSE AND FALSE.

Example 30

medium
Evaluate: NOT (A AND B) where A=TRUE, B=FALSE, then verify using De Morgan.

Example 31

medium
A guard says: 'enter if NOT (raining OR snowing)'. It is raining=TRUE, snowing=FALSE. Should the body run?

Example 32

medium
Evaluate: NOT (NOT TRUE OR FALSE).

Example 33

medium
For how many of the 8 rows of (A OR B) AND C is the result TRUE?

Example 34

hard
Simplify (A AND B) OR (A AND NOT B) using factoring.

Example 35

hard
Short-circuit trace: in code 'if (x != 0) AND (10 / x > 1)' with x = 0, does division by zero occur?

Example 36

hard
For how many of the 8 rows of (A OR B) AND (NOT B OR C) is the result TRUE? List the count.

Example 37

challenge
Find a single assignment of A, B, C that makes (A OR NOT B) AND (NOT A OR C) AND (B OR NOT C) FALSE.

Background Knowledge

These ideas may be useful before you work through the harder examples.

selection