Break Statement:
The break statement is used to jump out of a control statement.
break.java
public class Main {
public static void main(String[] args) {
int i;
for (i = 0; i < 10; i++) {
if (i == 2) {
break;
// it will move out of loop when i == 2
}
System.out.println(i);
}
}
}
Continue Statements:
The continue statement will skip the current iteration.
continue.java
public class Main {
public static void main(String[] args) {
int i;
for (i = 0; i < 10 ; i++) {
if (i == 2) {
continue;
// it will skip when i == 2
}
System.out.println(i);
}
}
}
Note : The break statement in Java is a powerful statement for controlling the flow of a loop. On the other hand, the continue statement is employed to skip the current iteration of a loop and proceed to the next one.