Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

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

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free