AP CSP Day 25: Conditionals
Share
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).
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")
}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.
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.
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.
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