AP CSP
AP Computer Science Principles / All lessons / Big Idea 3: Algorithms and Programming
3Big Idea 3: Algorithms and Programming
AP CSP topic 3.5

Boolean Expressions

A Boolean expression evaluates to true or false. Relational operators compare values: =, ≠, >, <, ≥, and ≤. Logical operators combine conditions: AND is true only when both sides are true, OR is true when at least one side is true, and NOT flips true to false. These expressions are how programs make decisions.

Picture it
ABA AND BA OR BNOT A
truetruetruetruefalse
truefalsefalsetruefalse
falsetruefalsetruetrue
falsefalsefalsefalsetrue
Truth table: AND is true only when both are true. OR is true when at least one is true. NOT flips the value.

Boolean Expressions vocabulary

  • Boolean expression: An expression that evaluates to true or false.
  • Relational operator: An operator that compares two values, such as > or ≠.
  • AND: True only if both conditions are true.
  • OR: True if at least one condition is true.

AP-style practice questions

Try each one, then open the answer. To save your progress, take this quiz in the interactive course.

Skill: Code Analysis
age ← 15
hasPermission ← false

1. What does (age ≥ 13) AND hasPermission evaluate to?

  1. (A) true
  2. (B) false
  3. (C) 15
  4. (D) An error
Show answer

(B) false AND needs both sides true. hasPermission is false.

Skill: Code Analysis
a ← 5
b ← 9

2. Which expression evaluates to true?

  1. (A) (a > b) OR (a = b)
  2. (B) NOT (a < b)
  3. (C) (a < b) OR (b < 0)
  4. (D) (a > 0) AND (b < 0)
Show answer

(C) (a < b) OR (b < 0) a < b is true, and OR needs only one side true.

Skill: Algorithms and Program Development

3. A ride requires riders to be at least 48 inches tall and no more than 78 inches tall. Which expression is true only for allowed heights h?

  1. (A) (h ≥ 48) OR (h ≤ 78)
  2. (B) (h ≥ 48) AND (h ≤ 78)
  3. (C) (h > 48) AND (h > 78)
  4. (D) NOT (h ≥ 48)
Show answer

(B) (h ≥ 48) AND (h ≤ 78) Both conditions must hold, so AND is needed. OR would allow every height.

Skill: Code Analysis

4. Which of the following is equivalent to NOT (score < 60)?

  1. (A) score > 60
  2. (B) score ≥ 60
  3. (C) score ≤ 60
  4. (D) score = 60
Show answer

(B) score ≥ 60 The opposite of "less than 60" is "60 or more".

Open 3.5 in the interactive course