AP CSA Unit 2 Day 26: Iteration Break In Nested Loops
Share
Unit 2, Selection & Iteration • Cycle 2
Day 26 Advanced Practice • Harder Difficulty
Focus: Break Scope
Hard
Iteration (break in nested loops)
Advanced Practice Question
Format: Iteration (break in nested loops)
What is printed?
What is printed?
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
break;
}
System.out.print(i + "," + j + " ");
}
}
Difficulty: Hard |
Topic: Iteration (break in nested loops) |
Cycle: 2 (Advanced)
Why This Answer?
For each i, the inner loop increments c when j=1, then breaks at j=2. That's 1 increment per outer iteration. Outer runs 3 times → c = 3.
Common Mistake
Watch Out!
Thinking `break` exits both loops (it exits only the inner loop).
AP Exam Strategy
`break` only exits the loop it is directly inside.
Master This Topic
This Cycle 2 HARD question tests break scope. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding break scope
- 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