AP CSP Day 3: Conditionals

Key Concepts

Conditional statements (IF, IF/ELSE) allow programs to make decisions based on Boolean conditions at runtime. The body of an IF block executes only when the condition evaluates to true; an ELSE block executes when it is false. AP CSP exam questions frequently present nested conditionals where only one branch executes, and students must identify which output or variable value results from a given input. Reading every condition carefully before tracing is essential.

📚 Study the Concept First (Optional) Click to expand ▼

Conditional Statements: IF and IF/ELSE

How Conditionals Work

A conditional lets a program take different actions based on whether a condition is true or false. The IF block runs only when the condition is true. The ELSE block runs when the condition is false. Only one branch ever executes for a given input.

Real-World Analogy

A thermostat: IF the temperature drops below 68, turn on the heat. ELSE, leave it off. The thermostat checks the condition once and acts accordingly every time.

Common Trap: Assuming both branches can execute for the same input. In an IF/ELSE structure, exactly one branch runs per condition check, never both.
Exam Tip: Substitute the given input value into the condition before looking at the answer choices. Decide which branch executes, then trace only that branch.
Big Idea 3: Algorithms & Programming
Cycle 1 • Day 3 Practice • Medium Difficulty
Focus: Conditionals

Practice Question

What is displayed after the following code runs?

score ← 85
IF score ≥ 90
{
   DISPLAY("A")
}
ELSE
{
   IF score ≥ 80
   {
      DISPLAY("B")
   }
   ELSE
   {
      DISPLAY("C")
   }
}
Why This Answer?

score is 85. The first condition (85 ≥ 90) is false, so execution enters the ELSE block. Inside the ELSE, the condition 85 ≥ 80 is true, so "B" is displayed. The inner ELSE block ("C") is skipped.

Why Not the Others?

A) 85 is not ≥ 90, so the first IF is false. B) The inner condition 85 ≥ 80 is true, so the inner ELSE does not execute. D) In an IF/ELSE structure, only one branch executes — never both.

Common Mistake
Watch Out!

Students sometimes evaluate all conditions independently instead of recognizing that IF/ELSE chains stop at the first true condition. Once a branch executes, all remaining branches are skipped.

AP Exam Tip

In IF/ELSE chains, evaluate conditions from top to bottom and stop at the first true condition. Only one branch in an IF/ELSE structure will ever execute.

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.