How do conditionals let a program make decisions, and how do nested conditionals handle several cases?
Topic 3.6/3.7 Conditionals and Nested Conditionals: conditional (IF/ELSE) statements select which code runs based on a Boolean condition, and nested conditionals handle multiple decision paths.
A focused answer to AP CSP Topics 3.6 and 3.7, covering IF and IF/ELSE selection, the role of the Boolean condition, nested conditionals for multiple paths, tracing which branch runs, and writing decision logic in AP CSP pseudocode.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topics 3.6 and 3.7) wants you to use conditional statements to make a program make decisions. An IF statement runs a block of code only when its Boolean condition is true; an IF/ELSE chooses between two blocks. Nested conditionals (a conditional inside another) handle multiple decision paths, such as grading into bands. You need to write decision logic and trace which branch runs for a given input.
The IF statement
IF (temperature > 30)
{
DISPLAY("It is hot")
}
The IF/ELSE statement
IF (score ≥ 50)
{
DISPLAY("Pass")
}
ELSE
{
DISPLAY("Fail")
}
A conditional without an ELSE simply does nothing when the condition is false, and the program continues with the statements after the IF block. With an ELSE, one of the two paths is always taken. This is the difference between "do this extra step if a condition holds" and "choose one of two paths".
Nested conditionals for multiple paths
When there are more than two outcomes, you nest a conditional inside a branch. Each level narrows the possibilities. Order the tests carefully: once you are inside an ELSE, you already know the outer condition was false, so the inner test only needs to distinguish the remaining cases.
A nested chain reads as a series of questions. "Is it the highest band? If not, is it the next band? If not, it must be the lowest." Each ELSE block has already ruled out everything tested above it, which is why the inner conditions can be simpler than they first appear. The depth of nesting matches the number of distinct outcomes minus one.
Why the condition must be Boolean
A conditional always tests a Boolean expression, one that evaluates to true or false. That expression usually comes from a relational comparison (score >= 90) or a logical combination (age >= 13 AND age < 65). Getting the condition right is most of the work: a correct branch structure with a wrong condition still gives wrong results. When you write a conditional, first decide exactly what Boolean question separates the cases, then build the branches around it.
Try this
Q1. For the code in the worked example, what is displayed when age ← 10? [1 point]
- Cue.
10 < 13is true, so the outerIFruns and"child"is displayed.
Q2. In an IF/ELSE statement, how many of the two blocks run each time? [1 point]
- Cue. Exactly one: the
IFblock when the condition is true, theELSEblock when it is false.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2022 (style)1 marksMultiple choice. Consider the following AP CSP pseudocode.
```
n ← 4
IF (n > 10)
{
DISPLAY("big")
}
ELSE
{
IF (n > 3)
{
DISPLAY("medium")
}
ELSE
{
DISPLAY("small")
}
}
```
What is displayed?
(A) big
(B) medium
(C) small
(D) nothing
Show worked answer →
The answer is (B).
n is 4. The outer condition n > 10 is false, so the ELSE branch runs. Inside it, n > 3 is true (4 > 3), so "medium" is displayed. (A) would need n > 10. (C) would need n <= 3. (D) is wrong because one branch always runs in an IF/ELSE.
Markers reward tracing nested conditionals by evaluating the outer condition first, then the inner one only in the branch that runs.
AP 2021 (style)3 marksFree response (code writing). Write AP CSP pseudocode that takes a numeric `score` and displays "A" for 90 or above, "B" for 80 to 89, and "C" for below 80.
Show worked answer →
A 3-point question on multi-way selection with nested conditionals.
IF (score ≥ 90)
{
DISPLAY("A")
}
ELSE
{
IF (score ≥ 80)
{
DISPLAY("B")
}
ELSE
{
DISPLAY("C")
}
}
Point 1: test the highest band first (score ≥ 90). Point 2: in the ELSE, test the next band (score ≥ 80); because we already know score < 90, this captures exactly 80 to 89. Point 3: the final ELSE handles everything below 80. A common error is testing score ≥ 80 first, which would label a 95 as "B".
Related dot points
- Topic 3.3/3.5 Mathematical and Boolean Expressions: programs evaluate arithmetic (including MOD) and Boolean expressions using relational and logical operators (AND, OR, NOT) that produce true or false.
A focused answer to AP CSP Topics 3.3 and 3.5, covering arithmetic operators and the MOD operator, relational operators, the Boolean operators AND, OR and NOT with truth tables, evaluating compound conditions, and the common uses of MOD such as testing even or odd.
- Topic 3.8 Iteration: iteration (REPEAT n TIMES and REPEAT UNTIL) repeats a block of code, with the number of repetitions controlled by a count or a condition.
A focused answer to AP CSP Topic 3.8, covering REPEAT n TIMES and REPEAT UNTIL loops in AP CSP pseudocode, counting iterations, accumulating values, infinite loops and off-by-one errors, and tracing loop execution.
- Topic 3.9 Developing Algorithms: an algorithm is a finite set of instructions that accomplishes a task, built by combining sequencing, selection and iteration, and different algorithms can solve the same problem.
A focused answer to AP CSP Topic 3.9, covering what an algorithm is, the three building blocks (sequencing, selection, iteration), expressing algorithms in pseudocode and language, that different algorithms can solve the same problem, and standard list algorithms.
- Topic 3.1 Variables and Assignments: a variable is a named reference to a stored value, and the assignment operator stores the value of an expression into a variable.
A focused answer to AP CSP Topics 3.1 to 3.3, covering variables as named storage, the assignment operator (the arrow) in AP CSP pseudocode, evaluating the right side first, updating variables, data types, and tracing assignment statements.
- Topic 1.4 Identifying and Correcting Errors: programs contain logic, syntax, runtime and overflow errors, and programmers find and fix them by testing with carefully chosen inputs and debugging.
A focused answer to AP CSP Topic 1.4, covering logic, syntax, runtime and overflow errors, testing with chosen inputs including edge cases, debugging strategies such as tracing and adding display statements, and how to describe testing in the Create task.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description — College Board (2025)