Boolean Logic Examples: 45 Problems with Answers

Worked examples of Boolean Logic to try before you open each solution, then practice problems with answers.

Worked Examples

Example 1

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

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

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

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 each one, 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.

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.

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

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.

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.

Read the full lesson on Boolean Logic

Background knowledge

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

selection