Unit 2 Cycle 2 Day 23: Iteration (while-loop tracing)

Unit 2, Selection & Iteration • Cycle 2
Day 23 Advanced Practice • Harder Difficulty
Focus: Loop Termination Hard Iteration (while-loop tracing)

Advanced Practice Question

Format: Iteration (while-loop tracing)

What is printed?
"apcs-keyword">int x = "apcs-number">10;
"apcs-keyword">int c = "apcs-number">0;

"apcs-keyword">while (x > "apcs-number">0)
{
    x -= "apcs-number">4;
    c++;
}

System.out.println(c);
Difficulty: Hard  |  Topic: Iteration (while-loop tracing)  |  Cycle: 2 (Advanced)
Why This Answer?

x goes 10→6→2→-2, so the loop runs 3 times and prints 3.

Common Mistake
Watch Out!

Stopping at x=2 and forgetting the loop runs one more time before x becomes ≤ 0.

AP Exam Strategy

The condition is checked before each iteration; updates happen inside.

Master This Topic

This Cycle 2 HARD question tests loop termination. Review Unit 2 concepts to build mastery of selection and iteration.

  • Understanding loop termination
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 2 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.