AP CSP Day 33: Internet Protocols

Big Idea 3: Algorithms & Programming
Cycle 2 • Day 33 Practice • Hard Difficulty
Focus: Conditionals

Practice Question

What is displayed after the following code runs?

x ← 15
y ← 10
IF x > y
{
   IF x - y > 10
   {
      DISPLAY("far apart")
   }
   ELSE
   {
      DISPLAY("close")
   }
}
ELSE
{
   DISPLAY("y is bigger")
}
Why This Answer?

First condition: x > y evaluates to 15 > 10 = true. Inside the nested IF: x - y > 10 evaluates to 15 - 10 = 5 > 10 = false. The ELSE branch executes, displaying "close".

Why Not the Others?

A) The difference (5) is not greater than 10. C) The outer condition x > y is true, so the outer ELSE does not execute. B) One of the branches must execute because the outer IF/ELSE covers all cases.

Common Mistake
Watch Out!

Students evaluate the outer condition correctly but then rush through the nested condition without computing the actual difference, or they confuse which ELSE pairs with which IF.

AP Exam Tip

In nested IF/ELSE structures, work from the outside in. Determine which outer branch executes first, then evaluate the inner conditions within that branch only.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.