Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

Write a Java program to demonstrate the usage of a break statement inside a While loop?

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++;  
    }  
}  
}  
LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud