AP CSP Day 25: Conditionals

Key Concepts

Nested conditionals occur when one IF statement appears inside another, creating decision trees with multiple outcomes. The order of conditions in an IF/ELSE IF chain matters because the first true condition executes and all remaining branches are skipped. AP CSP review questions on conditionals frequently involve multi-branch structures where students must identify which output results from a specific input value. A useful strategy is to substitute the given input into each condition in order and stop at the first true branch.

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

Conditionals Review: Nested and Multi-Branch

Nested Conditionals

A nested conditional places one IF statement inside another. The inner IF only executes if the outer IF condition is true. Indentation in pseudocode shows nesting level and helps identify which ELSE belongs to which IF.

IF / ELSE IF / ELSE Chains

In a multi-branch chain, conditions are tested in order. The first true condition executes its block, and all remaining branches are skipped. If no condition is true, the final ELSE block runs (if present).

Common Trap: Assuming multiple branches can execute for the same input. In a properly structured IF/ELSE IF/ELSE chain, exactly one branch executes per call.
Exam Tip: When given a specific input value, substitute it into each condition starting from the top. Stop at the first true condition. That branch and only that branch executes.
Big Idea 3: Algorithms & Programming
Cycle 1 • Day 25 Practice • Medium Difficulty
Focus: Conditionals

Practice Question

What is displayed after the following code runs?

temp ← 72
IF temp > 80
{
   DISPLAY("hot")
}
IF temp > 60
{
   DISPLAY("warm")
}
IF temp > 40
{
   DISPLAY("cool")
}
Why This Answer?

These are three separate IF statements (not IF/ELSE), so each one is evaluated independently. With temp = 72: 72 > 80 is false (skip), 72 > 60 is true (display "warm"), 72 > 40 is true (display "cool"). Both "warm" and "cool" are displayed.

Why Not the Others?

A) 72 is not greater than 80, so "hot" is not displayed. B) The third IF statement also evaluates to true, so "cool" is displayed too. D) The first condition is false, so "hot" is not included.

Common Mistake
Watch Out!

Students treat separate IF statements as an IF/ELSE chain, thinking that once one condition is true, the rest are skipped. Separate IF statements each evaluate independently.

AP Exam Tip

Critical distinction: separate IF statements all evaluate independently. IF/ELSE chains stop at the first true condition. Look for ELSE to determine which pattern is being used.

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.