Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
In Java, the break and continue are jump statements that ignore specific statements within the loop or abruptly terminate the loop without executing the test expression. These statements can be used within any loop, including for, while, and do-while loops.
Following is the Java program that demonstrates the use of break statements inside a While loop.
Code:
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++;
}
}
}
Output:
1
2
3
4
5
Following is the Java program that demonstrates the use of continue statement inside a While loop.
Code:
public class Example {
public static void main(String[] args) {
//initiating while loop
int a=1;
while(a<=10){
if(a==5){
//using continue statement
a++;
continue;//it will skip the remaining statement
}
System.out.println(a);
a++;
}
}
}
Output:
1
2
3
4
5
6
7
8
9
10
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.