8/14/25, 9:51 PM Java Break and Continue
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Java Break and Continue
❮ Previous Next ❯
Java Break
You have already seen the break statement used in an earlier chapter of this tutorial. It
was used to "jump out" of a switch statement.
The break statement can also be used to jump out of a loop.
This example stops the loop when i is equal to 4:
Example Get your own Java Server
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
System.out.println(i);
}
Try it Yourself »
Java Continue
https://www.w3schools.com/java/java_break.asp 1/6
8/14/25, 9:51 PM Java Break and Continue
The continue statement breaks one iteration (in the loop), if a specified condition occurs,
Tutorials Exercises Services
and continues with the next iteration in the loop.
Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
This example skips the value of 4:
Example
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
System.out.println(i);
}
Try it Yourself »
Break and Continue in While Loop
You can also use break and continue in while loops:
Break Example
int i = 0;
while (i < 10) {
System.out.println(i);
i++;
if (i == 4) {
break;
}
}
Try it Yourself »
https://www.w3schools.com/java/java_break.asp 2/6
8/14/25, 9:51 PM Java Break and Continue
Tutorials
Continue Exercises
Example Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
int i = 0;
while (i < 10) {
if (i == 4) {
i++;
continue;
}
System.out.println(i);
i++;
}
Try it Yourself »
?
Exercise
True or False:
The break statement can only be used within switch statements.
True
False
Submit Answer »
❮ Previous Next ❯
https://www.w3schools.com/java/java_break.asp 3/6
8/14/25, 9:51 PM Java Break and Continue
Tutorials Exercises Services Sign In
HTML
CSS Track your
JAVASCRIPT SQLprogress
PYTHON- it'sJAVA
free! PHP SignHOW
Up TOLog inW3.CSS C
COLOR PICKER
PLUS SPACES
https://www.w3schools.com/java/java_break.asp 4/6
8/14/25, 9:51 PM Java Break and Continue
Tutorials Exercises
GET CERTIFIED
Services
FOR TEACHERS
Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
https://www.w3schools.com/java/java_break.asp 5/6
8/14/25, 9:51 PM Java Break and Continue
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
Tutorials Exercises learning.
Services
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
Sign In
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.
https://www.w3schools.com/java/java_break.asp 6/6