3. Algorithms and Programming

Boolean Expressions

Boolean Expressions in Algorithms and Programming

students, imagine you are writing a program for a school club app that decides whether a student can enter a locked event. The app might need to check things like whether the student has a ticket, whether they are on the guest list, and whether the doors are open. To make that decision, the program uses Boolean expressions ✅. These are a key part of AP Computer Science Principles because programs often need to make choices based on true-or-false conditions.

Lesson objectives:

  • Explain what Boolean expressions are and how they work.
  • Use Boolean logic to reason about program decisions.
  • Connect Boolean expressions to algorithms, conditionals, and program flow.
  • Interpret examples of Boolean expressions in AP CSP style problems.
  • Summarize why Boolean expressions matter in real programs.

What Is a Boolean Expression?

A Boolean expression is any expression that evaluates to one of two values: $\text{true}$ or $\text{false}$. In computer science, these values are often used to answer yes-or-no questions. For example, the statement $\text{age} \ge 13$ is Boolean if $\text{age}$ is a number. If $\text{age} = 15$, then the expression is $\text{true}$. If $\text{age} = 10$, it is $\text{false}$.

Boolean expressions are named after George Boole, whose ideas helped create Boolean logic. In programming, Boolean expressions are important because they help a computer decide what to do next. A program can compare values, check conditions, and combine multiple tests into one decision.

Common comparison operators include:

  • $==$ means equal to
  • $\ne$ means not equal to
  • $>$ means greater than
  • $<$ means less than
  • $\ge$ means greater than or equal to
  • $\le$ means less than or equal to

For example:

  • $\text{score} \ge 80$
  • $\text{username} == $\text{

Study Notes

  • Review the key concepts covered in this lesson.

Practice Quiz

5 questions to test your understanding