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.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...