AP CSP Topic 3.7 Guided Notes - Nested Conditionals

Big Idea 3: Algorithms and Programming · Topic 3.7 · Guided Notes (Student)

Nested Conditionals — Guided Notes

Fill these in during class or catch up here if you were absent. Print this page or work on paper — then check yourself with the CFUs on the Topic 3.7 page.

Print these notesAll CSP topics

Today’s objectives

  • Write nested conditional statements — a conditional placed inside a branch of another conditional — to model a decision that depends on an earlier decision (LO AAP-2.I)
  • Determine the result of nested conditional statements by tracing outside-in, remembering the inner condition is tested only when the outer branch is taken (LO AAP-2.I)

Bell ringer

A roller coaster has one rule: you must be at least 48 inches tall to ride. Riders who ARE tall enough face a second rule — riders under age 12 must ride with an adult. The gate attendant must give each rider exactly ONE of three responses. Write the yes/no questions the attendant asks, IN ORDER, for: (A) 46 in, age 40 (B) 50 in, age 9 (C) 50 in, age 15.

Write 2–4 sentences: For rider A, did you ever need to ask about age? Why not? What does that tell you about the ORDER the two questions must be asked in, and which question depends on the other?

01. Conditionals Inside Conditionals

Key Vocabulary (LO AAP-2.I)

Term Definition (write it)
Conditional statement (IF)
IF-ELSE statement
Nested conditional statement
Outer conditional
Inner conditional

Conditionals Within Conditionals

  • For the inner conditional to run at all, the program must first .
  • Nesting is the correct structure whenever the second decision .
  • An inner conditional may sit in the outer statement's IF part, its ELSE part, or .

One IF Inside Another

The age check lives INSIDE the height branch, so it runs only for a tall-enough rider.

AP Pseudocode (what the exam tests)

height ← 50
age ← 15
IF(height ≥ 48)
{
  IF(age ≥ 12)
  {
    DISPLAY("Enjoy the ride")
  }
}

Python (the runnable version)

height = 50
age = 15
if height >= 48:
    if age >= 12:
        print("Enjoy the ride")

Output

Enjoy the ride

Run and edit this yourself in the coding exercises for this topic.

Two Separate IFs vs One Inside the Other

Separate conditionals

Nested conditionals

  • Two separate IF statements differ from a nest because separate IFs .
  • You must nest rather than use two separate IFs whenever .

AP TIP: When the second question must be skipped for some outcomes of the first, nesting is required — two separate IFs would still ask it.

Stop and think

  1. In two sentences, explain what makes a conditional 'nested,' and give a real example (not the ride) where a second question matters only after the first is answered.
  2. Write nested pseudocode for this rule: a site shows the 'Post' button only if a user is logged in AND, among logged-in users, only if their email is verified — otherwise show 'Verify your email.' Anyone not logged in sees 'Please log in.'
  3. Explain why the rule in the previous question needs NESTING rather than two separate IF statements.

Answer in complete sentences and write your pseudocode using IF/ELSE. Then check yourself with the matching CFUs on the Topic 3.7 page.

02. Which Branch Actually Runs

The Inner Check Waits on the Outer

  • To determine the result, evaluate the conditions in order.
  • When the outer condition is false, the inner condition is .
  • A short rider's age never matters because .

When the Outer Fails, the Inner Is Skipped

height is 44, so the outer condition is false — the age check never runs, even though 30 ≥ 12.

AP Pseudocode (what the exam tests)

height ← 44
age ← 30
IF(height ≥ 48)
{
  IF(age ≥ 12)
  {
    DISPLAY("Enjoy the ride")
  }
  ELSE
  {
    DISPLAY("Ride with an adult")
  }
}
ELSE
{
  DISPLAY("Too short to ride")
}

Python (the runnable version)

height = 44
age = 30
if height >= 48:
    if age >= 12:
        print("Enjoy the ride")
    else:
        print("Ride with an adult")
else:
    print("Too short to ride")

Output

Too short to ride

Run and edit this yourself in the coding exercises for this topic.

Trace the Gate, Rider by Rider

Same nested gate from the last slide. For each rider, decide the outer result, whether the inner condition is even checked, and the one message displayed. Fill in the blanks yourself.

Complete the empty cells.

Rider (height, age) Outer: height ≥ 48? Inner: age ≥ 12 checked? What DISPLAYs
(44, 30) No — 44 ≥ 48 is false Too short to ride
(50, 15) Yes — 50 ≥ 48 is true Yes — 15 ≥ 12 is true
(50, 9) Yes — 50 ≥ 48 is true Yes — 9 ≥ 12 is false
(47, 40) No — 47 ≥ 48 is false Not checked — outer was false Too short to ride

Watch out — “Every Condition Always Gets Checked”

Myth: In a nested conditional, both the outer and the inner condition are always evaluated, so a rider's age is checked no matter their height.

Explain why this is wrong:

Stop and think

  1. Trace the ride gate for a rider who is 50 inches and age 12. State the outer result, whether the inner condition is checked, and the exact message displayed.
  2. A rider is 46 inches and age 40. Explain, step by step, why the program never checks the age even though 40 ≥ 12 is true.
  3. Modify the gate so that riders UNDER 48 inches who are at least 18 get the message 'Staff only.' Where does the new conditional go — and why there?

Show every step of your trace. Then check yourself with the matching CFUs on the Topic 3.7 page.

Common AP Traps

Three ways Topic 3.7 loses points on the exam — one minute now, real points in May.

A false outer skips the inner entirely — in your own words:

Match each ELSE to its own IF — in your own words:

Trace outside-in, one path only — in your own words:

Nested Conditionals, in One Slide

  • A nested conditional is a conditional statement placed within a branch of another conditional.
  • Nest when the second decision depends on the first — the inner question is asked only if the outer branch is taken.
  • To determine the result, trace OUTSIDE-IN: evaluate the outer condition, then the inner only if that branch runs.
  • A false outer condition skips the entire inner conditional — the inner condition is never evaluated.

Exit check — I can…

  • ☐  write nested conditional statements to model a decision that depends on an earlier decision (LO AAP-2.I)
  • ☐  explain why the inner condition is evaluated only when the outer branch is taken (LO AAP-2.I)
  • ☐  determine the result of a nested conditional by tracing it outside-in (LO AAP-2.I)
  • ☐  match each ELSE to the correct IF in a nested structure (LO AAP-2.I)

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]