Power Your Software Testing
with AI and Cloud
Supercharge QA with AI for Faster & Smarter Software Testing

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.

Get 100 minutes of automation test minutes FREE!!