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

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.


HTML Image tag, code...
How to code in HTML...
HTML text tag...
HTML text, how to display...
Container responsive styles...
HTML container tag...
HTML container...
Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...