All 4 CS A units
AP Computer Science A · Unit 2 of 4

Selection and Iteration

25–35% of the exam4 lessons · 54 min

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.

Boolean logic & ifwhile & for loopsNested loopsAlgorithms & tracing

Lessons in this unit

Formulas in Unit 2

Truth of && and ||
a && b : true only if both true · a || b : true if either true
`!a` reverses a. Short-circuiting means the right operand may be skipped once the result is settled.
for loop header
for (init; test; update) { body }
init runs once; test is checked before each iteration; body then runs; update runs after the body; repeat until test is false.
Total inner executions (fixed bounds)
outer passes × inner passes = total inner-body runs
When the inner bound depends on the outer variable, add up the per-pass counts instead of multiplying.
Three-step swap
temp = a; a = b; b = temp;
The temporary variable preserves the first value so it is not lost when the second is copied in.

What examiners penalize here

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

  1. Unit 1 · Using Objects and Methods
  2. Unit 2 · Selection and Iteration
  3. Unit 3 · Class Creation
  4. Unit 4 · Data Collections

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.