Curriculum
break and continue Statements in Java are loop control statements used to manage the execution flow inside loops and switch-case statements. These statements help developers control program execution more efficiently by stopping or skipping iterations when required.
In this Core Java course in Jaipur, students will learn how break and continue statements work in Java, their syntax, practical examples, and real-world applications in software development.
These statements are widely used in:
Understanding break and continue statements in Java helps students write optimized and logical programs.
The break statement is used to immediately terminate:
When break executes:
break;
class BreakExample {
public static void main(String[] args) {
for(int i = 1; i <= 10; i++) {
if(i == 5) {
break;
}
System.out.println(i);
}
}
}
1
2
3
4
When:
i == 5
becomes true:
class WhileBreak {
public static void main(String[] args) {
int number = 1;
while(number <= 10) {
if(number == 6) {
break;
}
System.out.println(number);
number++;
}
}
}
1
2
3
4
5
break prevents execution from continuing into other cases.
class SwitchBreak {
public static void main(String[] args) {
int day = 2;
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
default:
System.out.println("Invalid Day");
}
}
}
The continue statement skips the current iteration and moves to the next iteration of the loop.
Unlike break:
continue;
class ContinueExample {
public static void main(String[] args) {
for(int i = 1; i <= 5; i++) {
if(i == 3) {
continue;
}
System.out.println(i);
}
}
}
1
2
4
5
When:
i == 3
becomes true:
class WhileContinue {
public static void main(String[] args) {
int number = 0;
while(number < 5) {
number++;
if(number == 3) {
continue;
}
System.out.println(number);
}
}
}
1
2
4
5
| break | continue |
|---|---|
| Terminates loop completely | Skips current iteration |
| Moves outside loop | Moves to next iteration |
| Used in loops and switch | Used only in loops |
Java supports labeled break for nested loops.
class LabeledBreak {
public static void main(String[] args) {
outer:
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(i == 2 && j == 2) {
break outer;
}
System.out.println(i + " " + j);
}
}
}
}
Java also supports labeled continue.
class LabeledContinue {
public static void main(String[] args) {
outer:
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(j == 2) {
continue outer;
}
System.out.println(i + " " + j);
}
}
}
}
Stopping transactions when balance is insufficient.
Skipping invalid login attempts.
Ending game loops under conditions.
Skipping corrupted records.
Exiting menu selection systems.
These statements help developers:
Many beginners confuse:
Incorrect continue placement may create infinite loops.
Example:
continue;
before increment may prevent loop termination.
Understanding break and continue helps students:
In this lesson, students learned:
These concepts are essential for Java programming and software development.
break terminates loop or switch execution immediately.
continue skips current iteration and moves to next iteration.
break stops loop completely, while continue skips current iteration only.
Yes, break is commonly used in switch-case statements.
Labeled break terminates outer loop in nested loops.
They are used in gaming applications, banking software, login systems, and menu-driven applications.
WhatsApp us