Break, Continue & Loop Control
Break and continue give you fine-grained control over loop execution. Break exits a loop early, while continue skips to the next iteration. These are essential tools for writing efficient loops. This is a foundational concept in enterprise application development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Java experience. Take your time with each section and practice the examples
30 min•By Priygop Team•Last updated: Feb 2026
Loop Control Statements
Example
public class LoopControl {
public static void main(String[] args) {
// BREAK — exit loop early
System.out.println("=== Break Example ===");
System.out.println("Finding first number divisible by 7:");
for (int i = 1; i <= 100; i++) {
if (i % 7 == 0) {
System.out.println("Found: " + i);
break; // Stop searching
}
}
// CONTINUE — skip current iteration
System.out.println("\n=== Continue Example ===");
System.out.println("Odd numbers from 1 to 10:");
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue; // Skip even numbers
}
System.out.print(i + " ");
}
System.out.println();
// Labeled break (exit outer loop)
System.out.println("\n=== Labeled Break ===");
outer:
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
if (i * j > 10) {
System.out.println("Breaking at i=" + i + ", j=" + j);
break outer;
}
System.out.print(i * j + " ");
}
System.out.println();
}
}
}Try It Yourself: Number Games
Try It Yourself: Number GamesJava
Java Editor
✓ ValidTab = 2 spaces
Java|34 lines|1137 chars|✓ Valid syntax
UTF-8