Java break

Last Updated: March 17, 2022

Java break statement terminates execution of the current look and continues executing the next lines of the code

Java while loop break example

int[] numbers = { 125, 132, 95, 116, 110 };
int i =0;
while(i<numbers.length){
     if(numbers[i]==95) break;
     System.out.println("Number is "+numbers[i]);
     i=i+1;
 }
 System.out.println("Out of the Loop");

Output

Number is 125
Number is 132

Out of the Loop

When the program controller meets the line if(numbers[i]==95) break; , the controller will return from the loop start executing the next lines of the program

Test