AP CSA Unit 2 Day 9: Iteration While Loop Tracing
Share
Unit 2, Selection & Iteration • Cycle 2
Day 9 Advanced Practice • Harder Difficulty
Focus: While Loop Tracing
Hard
Iteration (while-loop tracing)
Advanced Practice Question
Format: Iteration (while-loop tracing)
What is printed?
What is printed?
int x = 1;
while (x < 10) {
System.out.print(x + " ");
x = x * 2;
}
Difficulty: Hard |
Topic: Iteration (while-loop tracing) |
Cycle: 2 (Advanced)
Why This Answer?
x goes 20 → 14 → 8 → 2 → -4. The loop ran 4 times, so y is 4.
Common Mistake
Watch Out!
Assuming the loop stops when x becomes 2 (it stops only after the next subtraction makes x ≤ 0).
AP Exam Strategy
Track x after each update; the condition is checked at the top each time.
Master This Topic
This Cycle 2 HARD question tests while loop tracing. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding while loop tracing
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs