AP CSP Big Idea 1 Sequencing Selection Iteration
AP CSP Sequencing, Selection & Iteration: Complete Guide (2025‑2026)
Every algorithm is built from three fundamental control structures: sequencing (steps run in order), selection (steps run only if a condition is met), and iteration (steps run repeatedly). These three building blocks are sufficient to write any computable program. AP CSP tests your ability to trace through all three, predict outputs, and identify which structure is being used in a given code segment.
Contents
The Three Control Structures
Every algorithm uses some combination of these three. A program with no selection always does the same thing. A program with no iteration processes each input only once. A program with no sequencing has no defined order.
A program does the following: (1) reads a student’s score, (2) checks if the score is ≥60, (3) if yes, prints ‘Pass’ and adds 1 to a pass counter, (4) if no, prints ‘Fail’ and adds 1 to a fail counter, (5) repeats steps 1–4 for each student in the class.
Which control structures are present, and where?
All three: Sequencing — steps 1–4 execute in order. Selection — step 2 is an IF/ELSE that executes one of two branches based on the score. Iteration — step 5 repeats the entire block for each student. Real programs combine all three constantly.
Tracing Through Combinations
-
x ← 3→ x is 3 -
y ← x + 2→ y is 5 -
x ← y * x→ x is 15 -
DISPLAY(x)→ outputs 15 - Each line uses the current value of variables
total ← 0REPEAT 3 TIMES:- Pass 1:
total ← 0 + 5= 5 - Pass 2:
total ← 5 + 5= 10 - Pass 3:
total ← 10 + 5= 15
Consider this AP pseudocode:count ← 0
REPEAT 4 TIMES
IF count MOD 2 = 0
DISPLAY(count)
count ← count + 1
What does this program display?
Work through each iteration before revealing: what values of count are displayed?
Trace:
Iteration 1: count = 0. 0 MOD 2 = 0 → DISPLAY(0). count becomes 1.
Iteration 2: count = 1. 1 MOD 2 = 1 → not displayed. count becomes 2.
Iteration 3: count = 2. 2 MOD 2 = 0 → DISPLAY(2). count becomes 3.
Iteration 4: count = 3. 3 MOD 2 = 1 → not displayed. count becomes 4.
Output: 0 and 2. The combination of iteration + selection inside the loop displays only even values of count.
Which Structure Does This Use?
- IF / ELSE IF / ELSE keywords
- Conditional test (variable compared to value)
- Two or more branches, only one executes
- Result depends on the current state
- Example: assigning a grade based on score
- REPEAT N TIMES keyword
- REPEAT UNTIL keyword
- FOR EACH in list keyword
- A block of code that executes multiple times
- Loop variable or counter changes each pass
A student argues that this code uses iteration:IF score ≥ 90
grade ← “A”
ELSE IF score ≥ 80
grade ← “B”
ELSE
grade ← “C”
‘It goes through the conditions multiple times,’ she says.
Is the student correct? What is the key distinction?
No — this is selection, not iteration. The key distinction: iteration executes a block of code multiple times (different passes through the same code). Selection executes one of several branches once. This IF/ELSE IF/ELSE evaluates the conditions in sequence, but only one branch executes and each condition is checked at most once per execution. No code runs more than once.
Common Exam Pitfalls
REPEAT N TIMES always executes exactly N times. REPEAT UNTIL runs until a condition becomes true — it may run 0 times if the condition is already true, or run indefinitely if the condition never becomes true (infinite loop).
Each iteration of a loop uses the current value of all variables, including ones modified in previous iterations. Trace one iteration at a time, updating variable values as you go.
IF can appear without ELSE. Without ELSE, if the condition is false, nothing happens and execution continues after the IF block. With ELSE, exactly one of the two branches always executes.
If the loop body displays a value, a REPEAT 4 TIMES loop displays it exactly 4 times. Students sometimes count N+1 or N-1 by confusing the loop count with a counter variable that starts at 0.
Check for Understanding
1. Which control structure causes a block of code to execute only when a specific condition is true?
- Sequencing — steps execute in defined order.
- Selection — a block executes only if a condition is met.
- Iteration — a block executes repeatedly.
- Abstraction — details are hidden from the caller.
2. Consider:x ← 1
REPEAT 3 TIMES
x ← x * 2
DISPLAY(x)
What is displayed?
- 2
- 4
- 6
- 8
3. Consider these statements about control structures:
I. Sequencing ensures steps execute in a defined order.
II. Selection always requires both IF and ELSE branches.
III. Iteration allows a block of code to execute multiple times.
Which are correct?
- I only
- I and III only
- II and III only
- I, II, and III
4. A program checks whether each number in a list is positive, negative, or zero, and counts how many are in each category. Which control structures are required?
- Sequencing only — to process the list in order.
- Selection only — to classify each number.
- Sequencing and iteration only — to process each number in order.
- Sequencing, selection, and iteration — to process each number (iteration), classify it (selection), and execute steps in order (sequencing).
5. A REPEAT UNTIL loop has the condition: REPEAT UNTIL score ≥ 60. If score starts at 80, how many times does the loop body execute?
- Once — it checks the condition once and then executes.
- Zero times — the condition is already true before the first iteration.
- Until score reaches 60.
- Infinitely — because the condition is already satisfied.
6. What is the output of this pseudocode?total ← 0
FOR EACH num IN [2, 4, 6]
IF num > 3
total ← total + num
DISPLAY(total)
- 12 — all three numbers are added.
- 10 — only 4 and 6 are added.
- 6 — only the last number is added.
- 0 — the condition is never true.
Frequently Asked Questions
Code Trace Gauntlet
Predict each output before revealing. The AP exam frequently combines sequencing, selection, and iteration in a single trace question.
y is assigned before x changes to 10. What displays?
8 y = x+3 = 5+3 = 8 (evaluated when x was 5). Changing x to 10 afterward does not retroactively change y. Sequencing: statements execute in written order.
Which values are displayed?
0 2 4 count goes 0,1,2,3,4. Even values (MOD 2 = 0): 0, 2, 4 are displayed.
Only values > 2 are added. What is total?
12 Values > 2: 3, 4, 5. Sum = 3+4+5 = 12.
result is used before it is defined. Statements execute in sequence — line 1 before line 2. Fix: assign result before displaying it.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com