Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
In Java, the break and continue are jump statements that ignore specific statements within the loop or abruptly terminate the loop without executing the test expression. These statements can be used within any loop, including for, while, and do-while loops.
Following is the Java program that demonstrates the use of break statements inside a While loop.
Code:
public class Example {
public static void main(String[] args) {
//initiating while loop
int a=1;
while(a<=10){
if(a==5){
//using break statement
a++;
break;//it will break the while loop
}
System.out.println(a);
a++;
}
}
}
Output:
1
2
3
4
5
Following is the Java program that demonstrates the use of continue statement inside a While loop.
Code:
public class Example {
public static void main(String[] args) {
//initiating while loop
int a=1;
while(a<=10){
if(a==5){
//using continue statement
a++;
continue;//it will skip the remaining statement
}
System.out.println(a);
a++;
}
}
}
Output:
1
2
3
4
5
6
7
8
9
10
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud