Selection and Iteration
What this unit covers
The topics below follow the published CS A course framework for Unit 2. This unit is worth 25–35% of the exam, so budget your time against that rather than against how long the unit takes to teach.
Lessons in this unit
- Boolean Logic & if Statements13 min · 3 objectivesEvaluate boolean expressions using relational and logical operators · Trace `if` / `else` statements to determine which branch runs · Combine conditions with `&&`, `||`, and `!`
- while & for Loops14 min · 3 objectivesTrace a `while` loop, tracking the condition and update each pass · Read the three parts of a `for` loop header: initialize, test, update · Accumulate a running total or count across loop iterations
- Nested Loops14 min · 3 objectivesTrace a loop nested inside another loop · Count the total number of times an inner body executes · Handle an inner loop whose bound depends on the outer variable
- Algorithms & Tracing13 min · 3 objectivesHand-trace an algorithm by tracking every variable through each step · Predict how many times a loop runs when its variable changes by more than one · Follow a value-swap sequence using a temporary variable
Formulas in Unit 2
What examiners penalize here
- The idiom `x % 2 == 0` tests for even; `x % 2 != 0` (or `== 1` for positive x) tests for odd. Expect this pattern in tracing questions and in FRQ logic.
- To trace a loop, make a small table with a column per variable and one row per pass. Writing the value after each iteration prevents off-by-one errors on the final count.
- When the inner bound is the outer variable (`j <= i`), do not multiply — add the per-row counts. A triangular pattern like 1 + 2 + 3 is the tell.
- For swap questions, resist the urge to assume a = b overwrites both. Trace all three statements: the temporary variable is what makes the exchange work correctly.
Practice CS A
Our practice bank is drawn from across the whole course rather than filtered to one unit, which is closer to how the exam asks anyway — it will not tell you which unit a question is testing.
Questions about this unit
How much of the AP Computer Science A exam is Unit 2?
Unit 2, Selection and Iteration, is worth 25–35% of the CS A multiple-choice section according to the published course framework. Across all 4 units that makes it one of the heaviest units on the exam, and worth front-loading.
What topics are covered in CS A Unit 2?
Selection and Iteration covers Boolean logic & if, while & for loops, Nested loops and Algorithms & tracing.
How should I study CS A Unit 2?
Read the 4 lessons below first — about 55 minutes — then work practice questions on these topics. Finish with practice questions and read the explanation for every one you get right by elimination as well as the ones you miss.
All 4 units of AP Computer Science A
Unit names, topics and exam weights follow the published College Board course framework for AP Computer Science A. AP® is a trademark registered by the College Board, which does not endorse this site.