- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
In Java, the break and continue statements are used to control the flow of loops. These statements can be used inside any loops such as for, while, and do-while loops.
Break Statement
The break statement is used to terminate a loop immediately. When a break statement is encountered inside a loop, the loop iteration stops, and control returns to the first statement after the loop. This is useful when you want to exit a loop based on a specific condition.
Example:
class GFG {public static void main(String[] args) {for (int i = 0; i < 10; i++) {if (i == 5)break;System.out.println("i: " + i);}System.out.println("Out of Loop");}}Copied!✕CopyOutput:
i: 0i: 1i: 2i: 3i: 4Out of LoopCopied!✕CopyIn this example, the loop terminates when i equals 5.
Continue Statement
The continue statement is used to skip the current iteration of a loop and proceed to the next iteration. This is useful when you want to skip certain iterations based on a specific condition.
Example:
Java Break and Continue - W3Schools
Good to Remember: break = stop the loop completely. continue = skip this round, but keep looping.
See results only from w3schools.comTry It Yourself
The W3Schools online code editor allows you to edit code and view the result in …
W3Schools Tryit Editor
The W3Schools online code editor allows you to edit code and view the result in …
How do I exit a while loop in Java? - Stack Overflow
Oct 31, 2011 · To exit a while loop, use Break; This will not allow to loop to process any conditions that are placed inside, make sure to have this inside the loop, as …
Java break Statement (With Examples) - Programiz
- In the case of nested loops, the breakstatement terminates the innermost loop. Here, the break statement terminates the innermost whileloop, and control jumps to the outer loop.
Break and Continue statement in Java - GeeksforGeeks
Mar 6, 2026 · Break and continue are jump statements used to alter the normal flow of loops. They help control loop execution by either terminating the loop early or skipping specific iterations. These …
break Keyword in Java: Usage & Examples - DataCamp
Learn how to use the `break` keyword in Java to terminate loops and switch statements early. Includes syntax, practical examples, and best practices. Master control flow with `break` in Java.
Searches you might like
Mastering `while` and `break` in Java - javaspring.net
Jan 16, 2026 · The while loop and the break statement are essential tools in Java programming. The while loop allows you to execute a block of code repeatedly as long as a certain condition is true, …
Master Java Break & Continue: A Deep Dive with Examples
Oct 13, 2025 · The break and continue statements are fundamental for writing precise and efficient loops in Java. They give you the fine-grained control you …
How to Exit a While Loop in Java - Delft Stack
Feb 2, 2024 · This tutorial introduces how you can exit a while-loop in Java and handle it with some example codes to help you understand the topic further. The while-loop is one of the Java loops used …
How Can You Effectively Break a While Loop in Programming?
Learn how to break a while loop effectively with clear examples and best practices. This guide explains different methods to exit a while loop in programming languages like Python and Java.
How to Properly Exit a While Loop in Java? - CodingTechRoom
Learn effective methods to terminate a while loop in Java, including code examples and common mistakes.