Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
A break statement terminates the loop immediately, and the control returns to the next statement. You can break a loop or switch statement using Java's break statement. It terminates the program's current flow at the specified condition. In the case of an inner loop, it just breaks the inner loop.
Following is the Java program that demonstrates the use of break statements inside a While loop.
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++;
}
}
}
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