</>
Skip to content
Java lessons (18/47)

Java — Break Continue

break

for (int i = 0; i < 10; i++) {
    if (i == 5) break;
    System.out.println(i);
}
// Output: 0 1 2 3 4

continue

for (int i = 0; i < 10; i++) {
    if (i % 2 == 0) continue;
    System.out.println(i);
}
// Output: 1 3 5 7 9

Labeled break

outer:
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        if (j == 1) break outer;
        System.out.println(i + ", " + j);
    }
}

Mini Practice

  1. Use break
  2. Use continue
  3. Practice labeled break
  4. Exit nested loops

Up Next

Continue with Arrays - Array operations.

Related Topics

Frequently Asked Questions about Break Continue

What is Break Continue in Java?

Break Continue is a fundamental concept in Java. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Break Continue?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Break Continue.

Why is Break Continue important in Java?

Break Continue is essential for Java development. Understanding this concept will help you write better code and solve real-world problems more effectively.