Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
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++;
}
}
}
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.