PrepGo

Boolean Expressions - AP Computer Science Principles Study Guide

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Learn with study guides reviewed by top AP teachers. This guide takes about 13 minutes to read.

Getting Started

Computers are powerful because they can make decisions. A video game needs to know if a player has leveled up, a banking app must decide if a password is correct, and a navigation system has to determine the fastest route. All of these complex decisions are built from simple true-or-false questions, which are evaluated using Boolean expressions.

What You Should Be Able to Do

  • Evaluate expressions that use relational operators (e.g., >, <, =).

  • Evaluate expressions that use logical operators (AND, OR, NOT).

  • Trace the evaluation of a compound expression that combines multiple operators.

  • Explain how the result of a Boolean expression can control the flow of a program.

Key Concepts & Application

The Core Idea

At the heart of every decision a computer makes is a simple concept: the Boolean value. A Boolean value can only be one of two things: true or false. Think of it like a light switch (on or off) or a simple yes/no answer. There is no middle ground.

An expression is a combination of values, variables, and operators that a computer evaluates to produce a single new value. A Boolean expression is any expression that results in a true or false value. For example, the question "Is the score greater than 100?" can be written as the expression score > 100. If score is 101, the expression evaluates to true; if score is 99, it evaluates to false. Programs use these results to choose which path to take, forming the basis of all logic and control.

Logic & Application

To build Boolean expressions, we use two types of operators: relational and logical.

Relational Operators

A relational operator is a symbol used to compare two values. The result of this comparison is always a Boolean value.

OperatorMeaningExample (a is 5, b is 10)Result
=Equal toa = 5true
Not equal toa ≠ btrue
>Greater thana > bfalse
<Less thana < btrue
Greater than or equal toa ≥ 5true
Less than or equal tob ≤ afalse

Logical Operators

A logical operator is used to modify or combine existing Boolean values to form more complex expressions.

OperatorLogicExample (a is true, b is false)Result
ANDReturns true if both operands are true.a AND bfalse
ORReturns true if at least one operand is true.a OR btrue
NOTReturns the opposite of the operand.NOT btrue

Annotated Pseudocode Examples

Boolean expressions are most commonly used to control selection statements, such as an IF block. The code inside the IF block only runs if its condition evaluates to true.


temperature <- 85

isRaining <- false


// This condition uses both a relational (>) and a logical (AND) operator.

// It checks if it's hot AND it's not raining.

IF (temperature > 80 AND isRaining = false)

{

  // This block will execute because both parts of the condition are true.

  DISPLAY("It's a great day for the beach!")

}

playerLevel <- 12

hasKey <- false


// This condition uses a logical OR operator.

// It checks if the player has a high enough level OR has the key.

IF (playerLevel > 20 OR hasKey = true)

{

  // This block will NOT execute because both parts of the condition are false.

  DISPLAY("You may enter the castle.")

}

ELSE

{

  DISPLAY("You are not ready to enter the castle.")

}

Tracing & Analysis

When expressions have multiple operators, they are evaluated in a specific order: NOT is evaluated first, then AND, and finally OR. Parentheses () can be used to force a different order of evaluation, just like in mathematics.

Logic Trace

Let's trace the evaluation of a complex expression. Assume the following variable values:

score <- 88

isVeteran <- false

priorityLevel <- 4

Now, evaluate the expression: (score > 90 OR isVeteran = true) AND priorityLevel < 5

  1. Evaluate expressions inside parentheses first.

    • score > 90 becomes 88 > 90, which is false.

    • isVeteran = true becomes false = true, which is false.

    • The parenthetical expression is now (false OR false).

    • false OR false evaluates to false.

  2. Substitute the result back into the main expression.

    • The expression is now: false AND priorityLevel < 5
  3. Evaluate the remaining operators.

    • priorityLevel < 5 becomes 4 < 5, which is true.

    • The expression is now: false AND true.

  4. Calculate the final result.

    • false AND true evaluates to false.

The entire Boolean expression evaluates to false.

Key Terminology & Logic

Operator / KeywordPurpose
a = bCompares a and b for equality.
a ≠ bCompares a and b for inequality.
a > b, a < bCompares a and b to see which is greater or less.
a ≥ b, a ≤ bCompares a and b including equality.
a AND bEvaluates to true only if both a and b are true.
a OR bEvaluates to true if a is true, or if b is true, or if both are true.
NOT aInverts the value of a; NOT true is false, NOT false is true.

Core Concepts & Terminology

  • Boolean Value: A data type that can hold only one of two values: true or false. It is the fundamental unit of logic in computing.

  • Expression: A segment of code that combines values, variables, and operators and is evaluated to produce a single resulting value.

  • Relational Operator: An operator (such as =, >, or ) that tests the relationship between two values and produces a Boolean result.

  • Logical Operator: An operator (AND, OR, NOT) that modifies or combines Boolean values to create more complex logical expressions.

  • Core Logic (Selection): Boolean expressions are the foundation of selection, which allows a program to execute different code blocks based on a condition.

    
    IF (condition)
    
    {
    
      // This code runs only if the 'condition' expression evaluates to true.
    
    }
    

    The condition must be a Boolean expression.

Core Skill Check

  • Logic Tracing: Given a <- 10 and b <- 20, what is the final value of the expression (a > 5) AND (b = 10 OR a ≠ 10)?

  • Debugging: A program to check if a user is a teenager has a bug. Identify the logic error: age <- 13, IF (age > 13 AND age < 19){ DISPLAY("User is a teen.") }.

  • Application: Describe a real-world rule for a streaming service that would require an AND operator in its logic (e.g., for allowing a user to watch a movie).

Common Misconceptions & Clarifications

  • Confusing = (Comparison) with <- (Assignment): In pseudocode, = asks "are these two things equal?" and results in true or false. In contrast, <- takes the value on the right and assigns it to the variable on the left.

  • "OR means only one can be true": In logic, OR is inclusive. true OR true evaluates to true. It means "at least one is true."

  • Forgetting Order of Operations: Without parentheses, NOT is always evaluated first, then AND, then OR. The expression NOT false AND false evaluates to true AND false, which is false.

  • Mixing up > with : A common source of errors is forgetting to include the "or equal to" case. score > 90 is false if score is exactly 90, while score ≥ 90 is true.

Summary

Boolean expressions are the building blocks of programmatic decision-making. They use relational operators to compare values and logical operators to combine or modify true/false conditions. By evaluating these expressions, a program can determine which actions to take, enabling it to respond dynamically to different inputs, states, and user interactions. Mastering the evaluation of these expressions is fundamental to understanding how algorithms control the flow of execution and create complex, intelligent behavior from simple, binary logic.