AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Java Break & Continue


Java Tutorial » Java Break & Continue

Java Break & Continue are used to skip some statements inside the loop or terminate the loop immediately without checking the test expression.
Break & continue are called jump statements

Java Break: statement is used to terminate the loop immediately.

Example:
public class Main {
public static void main(String[] args) {
for (int x = 10; x < 22; x++) {
if (x == 15) {
break;
}
System.out.println(x);
}
}
}

Output: 10
11
12
13
14



Java Continue, example


Continue statement is used to skip the current iteration of a loop.

We use continue statement inside any types of loops such as for, while, and do-while loop.

Example:
public class Main {
public static void main(String[] args) {
for (int x = 11; x < 17; x++) {
if (x == 15) {
continue;
}
System.out.println(x);
}
}
}

Output: 11
12
13
14
16



Break & Continue in While Loop


Example: Break Example
public class Main {
public static void main(String[] args) {
int x = 11;
while (x < 18) {
System.out.println(x);
x++;
if (x == 15) {
break;
}
}
}
}
Output:
11
12
13
14


Example: Continue Example
public class Main {
public static void main(String[] args) {
int x = 11;
while (x < 21) {
if (x == 15) {
x++;
continue;
}
System.out.println(x);
x++;
}
}
}
Output:
11
12
13
14
16
17
18
19
20




java break: for loop, while, foreach, line, if, label, while loop, out of for loop, stream java break continue, return, label, if statement, for loo[, nesteed loop, example, condition
Java Break & Continue - java

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...