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.

💻 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:

Example 1: break exits the loop
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");
    }
}
Running…

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:

Example 2: continue skips even numbers
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 + " ");
        }
    }
}
Running…

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:

Example 3: while(true) with break as exit
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");
    }
}
Running…

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.

1
⚠ Thinking break exits the method, not just the loop

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
2
⚠ continue in a for loop still runs the update

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++;
}
3
⚠ break in a nested loop only exits the inner loop

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
        }
    }
}
4
⚠ Expecting continue to skip the loop update

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.

🎓 AP Exam Tip

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.

⚠ Watch Out!

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)

Your Score: 0 / 0
1. What is printed?
for(int i=1;i<=5;i++){ if(i==3) break; System.out.print(i+" "); }
2. What is printed?
for(int i=1;i<=5;i++){ if(i==3) continue; System.out.print(i+" "); }
3. What is the difference in output between break and continue in the same loop position?
4. How many times does the loop body fully execute?
for(int i=0;i<10;i++){ if(i%3==0) continue; System.out.println(i); }
5. What is printed after this code completes?
for(int i=0;i<5;i++){ if(i==2) break; }
System.out.println("done");
6. What bug exists in this while loop with continue?
int i=0;
while(i<5){ if(i==2) continue; System.out.print(i); i++; }
7. What is printed?
outer: for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(j==1) break; System.out.print(i+""+j+" "); }}
8. Which statement about continue in a FOR loop is TRUE?

❓ Frequently Asked Questions

What does break do in Java?

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.

What does continue do in Java?

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.

What is the difference between break and continue?

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.

Does continue skip the update step in a for loop?

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.

What happens to code after a loop when break is used?

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.

TC

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

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]