Boolean Expressions & Operators (College Board AP® Computer Science Principles): Study Guide

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Boolean values & comparisons

What is a Boolean value?

  • A Boolean value is a data type that can only be true or false

  • Booleans are fundamental to decision-making in programs: conditions are evaluated to produce a Boolean result

  • Relational operators compare two values and return a Boolean result

Operator

Meaning

Example

Result

=

Equal to

5 = 5

true

Not equal to

5 ≠ 3

true

<

Less than

3 < 5

true

>

Greater than

5 > 8

false

Less than or equal to

5 ≤ 5

true

Greater than or equal to

3 ≥ 5

false

Boolean operands

  • Boolean operands are the values passed into a Boolean operation and can be:

    • Literal Boolean values (true or false)

    • Variables that hold Boolean values (isLoggedIn, isPassing)

    • Relational expressions that evaluate to a Boolean (score ≥ 50)

  • Comparison expressions evaluate to true or false before being used in a conditional or logic statement

Boolean logic operators

How are Boolean expressions combined?

  • Logic operators allow Boolean values to be combined to form more complex conditions

  • AP CSP pseudocode uses three logic operators: NOT, AND, and OR

Operator

Description

Example

Result

NOT

Reverses a Boolean value

NOT true

false

AND

Returns true only if both operands are true

true AND false

false

OR

Returns true if at least one operand is true

true OR false

true

Logic operators in practice

score ← 72
isPassing ← score ≥ 50
isHonors ← score ≥ 90
DISPLAY(isPassing AND NOT isHonors)
 
  • isPassing is true (72 ≥ 50), isHonors is false (72 < 90), NOT isHonors is true

  • true AND true evaluates to true, so the program displays true

Truth tables

  • A truth table shows every possible combination of Boolean inputs and the corresponding output for each logic operator

A

B

A AND B

A OR B

true

true

true

true

true

false

false

true

false

true

false

true

false

false

false

false

A

NOT A

true

false

false

true

Examiner Tips and Tricks

  • AND requires both conditions to be true — if either is false, the whole expression is false. OR only returns false when both conditions are false. When evaluating complex Boolean expressions, simplify one operator at a time from the inside out.

  • For the AP Create Performance Task, Boolean expressions drive the conditionals and loops your program must include — be prepared to explain how a condition in your code determines program behavior.

Worked Example

What is the value of the following expression?

NOT (3 > 5) AND (4 = 4)
  

(A) true

(B) false

(C) 3

(D) 4

[1]

Answer:

(A) true [1 mark]

  • NOT (3 > 5) evaluates to NOT false = true, and 4 = 4 is true, so true AND true evaluates to true

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.