Skip to main content
← AP CSA Study Guide

Unit 2 · Foundational

Boolean Logic and Conditionals

Where a program starts making choices. The unit covers building boolean expressions, ordering branches so they do not overlap, and the short-circuit behavior that lets a condition guard itself against its own errors.

What a strong answer looks like

A strong Unit 2 answer evaluates each subcondition separately, then states which branch runs first and why the later branches are skipped.

Topics in this unit

1

Boolean Operators

Practice this topic →

Know

And requires both operands true; or requires at least one; not inverts. De Morgan rules let a negated compound be rewritten without the outer negation.

Apply

Build a truth table for an unfamiliar condition rather than reasoning about it in prose.

Watch out

Negating a compound condition by negating each part without swapping and with or.

Study move

Rewrite a negated compound condition using De Morgan rules and confirm both forms agree on every case.

2

If/Else Tracing

Practice this topic →

Know

An else-if chain runs at most one branch, while separate if statements can all run. The order of the branches therefore changes the result when ranges overlap.

Apply

Trace a classifier at the exact boundary values, not at values comfortably inside each range.

Watch out

Writing overlapping conditions in an order where an earlier branch swallows a later one.

Study move

Trace a grade classifier at 89, 90, 79, and 80 and confirm each lands in the intended branch.

3

Compound Conditions

Practice this topic →

Know

Compound conditions combine comparisons, and each part must be evaluated independently before the whole can be judged.

Apply

Evaluate each comparison to true or false first, then combine, rather than reading the condition as a sentence.

Watch out

Chaining comparisons as in mathematics. Java requires each comparison to be written out and joined explicitly.

Study move

Rewrite a range check as an explicit conjunction of two comparisons and test both endpoints.

4

Short-Circuit Logic

Practice this topic →

Know

And stops as soon as a false operand is found; or stops at the first true one. The remaining operands are never evaluated, which is what makes a guard clause work.

Apply

Place the check that prevents an error before the operation that could cause it, relying on short-circuiting to protect it.

Watch out

Reversing the order of a guard, so the risky operation runs before the check that was meant to prevent it.

Study move

Write a condition that safely tests a property of a possibly-null object, then swap the order and explain what breaks.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Testing conditions at their exact boundaries rather than in the middle of a range
  • Ordering else-if branches so no earlier branch absorbs a later one
  • Using short-circuit evaluation deliberately as a guard

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • switch statements. Taught in some classes; the exam favors if and else-if.
  • Ternary operator. Common in class code, though the exam rarely depends on it.

Mastery checklist

  • Build a truth table for a compound condition.
  • Apply De Morgan rules to a negated compound.
  • Trace an else-if chain at every boundary value.
  • Explain why a guard clause must come first in a short-circuit condition.

Check yourself

  • When do separate if statements behave differently from an else-if chain?
  • What exactly does short-circuit evaluation skip?
  • Why can a range check not be written as a single chained comparison in Java?

Modeling drill

Write a condition that accepts an age between 13 and 19 inclusive, then state what it returns at 12, 13, 19, and 20.

Boolean expressionDe Morganelse-if chainShort-circuitGuard clauseBoundary value