AP CSA Break Continue
break and continue in AP CSA: Complete Guide (2025-2026)
break and continue in AP CSA are loop control statements that alter the normal flow of iteration, and they appear as MCQ traps on the AP Computer Science A exam in Unit 2 (25–35%). break immediately exits the entire loop — no more iterations run. continue skips the rest of the current iteration and jumps to the update step, then checks the condition again. The AP exam uses these to test whether students can accurately trace which iterations complete and which get cut short.
📄 Table of Contents
💻 Code Examples — Predict First
Before running each example, write down your prediction. This is the single most effective AP exam study technique.
🤔 Predict the output before running:
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 5) {
break;
}
System.out.print(i + " ");
}
System.out.println("done");
}
}
0 1 2 3 4 done — When i=5, break fires and the loop exits immediately. 5 is never printed. Execution jumps to the println("done") after the loop.
🤔 Predict the output before running:
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
continue;
}
System.out.print(i + " ");
}
}
}
1 3 5 7 9 — When i is even, continue skips the print statement for that iteration. The loop variable still increments normally. Only odd values are printed.
🤔 Predict the output before running:
public class Main {
public static void main(String[] args) {
int i = 0;
while (true) {
if (i >= 5) {
break;
}
System.out.print(i + " ");
i++;
}
System.out.println("exited");
}
}
0 1 2 3 4 exited — The infinite while(true) loop is the standard sentinel pattern. When i reaches 5, break fires and execution continues after the loop.
❌ Common Pitfalls
These are the mistakes students most often make on the AP CSA exam with break and continue AP CSA. Study them carefully.
break only exits the innermost loop it is in. Code after the loop continues running normally. The AP exam tests this by asking what prints AFTER the loop when break is used.
for (...) {
if (cond) {
break;
}
}
System.out.println("still runs!"); // This DOES execute
When continue fires in a for loop, the update step (i++) still runs before rechecking the condition. Only the remaining body statements are skipped. In a while loop, you must ensure the update runs before continue or you get an infinite loop.
// While loop infinite loop trap:
int i=0;
while(i<10){
if(i==5) {
continue; // i never increments past 5!
}
i++;
}
In a nested loop, break only exits the loop it is directly inside. The outer loop continues. If you need to exit both loops, you need a flag variable or labeled break (not tested on AP exam).
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(j==1) {
break; // exits inner only, outer continues
}
}
}
Students sometimes think continue skips everything including the for loop update (i++). It does NOT — only the body statements after continue are skipped. The update always runs in a for loop.
On the AP CSA exam, when you see a loop with break or continue, trace it manually with a small table. For break: mark the iteration where it fires and cross out all subsequent iterations. For continue: mark skipped iterations but keep the update running.
A while(true) loop with break is a legitimate and common pattern. It is NOT automatically an error. The AP exam uses it to test whether students understand that break is a valid loop-exit mechanism.
✍ Check for Understanding (8 Questions)
for(int i=1;i<=5;i++){ if(i==3) break; System.out.print(i+" "); }
for(int i=1;i<=5;i++){ if(i==3) continue; System.out.print(i+" "); }
for(int i=0;i<10;i++){ if(i%3==0) continue; System.out.println(i); }
for(int i=0;i<5;i++){ if(i==2) break; }
System.out.println("done");
int i=0;
while(i<5){ if(i==2) continue; System.out.print(i); i++; }
outer: for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(j==1) break; System.out.print(i+""+j+" "); }}
❓ Frequently Asked Questions
break immediately exits the innermost loop it is in. No more iterations run. Execution continues with the first statement after the closing brace of the loop. break does NOT exit the method.
continue skips the remaining statements in the current loop body and jumps to the next iteration. In a for loop, the update step (i++) still runs. In a while loop, the condition is rechecked immediately.
break ends the loop entirely. continue ends only the current iteration and moves to the next. After break, no more iterations run. After continue, the loop continues with the next iteration.
No. In a for loop, continue jumps directly to the update step (like i++), then rechecks the condition. Only the body statements after continue are skipped. This is different from a while loop where you must be careful to update the variable before calling continue.
Code after the loop always executes normally, regardless of whether the loop exited via break or via its condition becoming false. break only skips the remaining loop iterations, not the code that follows the loop.
Tanner Crow — AP CS Teacher & Tutor
11+ years teaching AP Computer Science at Blue Valley North High School (Overland Park, KS). Verified Wyzant tutor with 1,845+ hours, 451+ five-star reviews, and a 5.0 rating. His AP CSA students score 5s at more than double the national rate.
- 54.5% of students score 5 on AP CSA (national avg: 25.5%)
- 1,845+ verified tutoring hours • 5.0 rating
- Free 1-on-1 tutoring inquiry: Wyzant Profile
🔗 Related Topics
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]