Java Break & Continue Statements
`break` and `continue` give you fine-grained control over loop execution. `break` terminates the entire loop immediately, while `continue` aborts only the current iteration and jumps directly to the next cycle.
"Think of reading a playlist: `break` means stopping the music player completely and walking away. `continue` means pressing the "Skip Track" button to start the next song immediately."
Deep Dive: How It Works
`break`: Immediately halts the enclosing loop and transfers control to the line following the loop.
`continue`: Skips whatever remaining lines are in the current iteration and advances to the loop update step.
Labeled breaks: Java allows labeling outer loops (e.g. `outer: for(...)`) to break out of nested loops directly.
Syntax Blueprint
for (int i = 1; i <= 10; i++) {
if (i == 3) continue; // skip 3
if (i == 7) break; // stop at 7
System.out.println(i);
}Use continue to skip unwanted items and break for early termination on matches.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Putting code after break or continue in the same blockWhy it happens: Java compiler detects this as "unreachable statement" and will reject the build.
How to fix: Ensure break and continue are the last statements executed in that branch.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Stop loop when target found
Iterate from 1 to 10.
If i == 4, print "Target 4 Found!" and break.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.