The break
statement in Java is used to exit the program from a loop. After a break
statement is called, control is returned from the loop to the next statement outside the loop. break
statements are used in scenarios where we need to exit the loop on a specific condition, or when the number of iterations is uncertain.
break;
class BreakExample {public static void main(String args[]){int i=0;// Initially decrementing loop is set to run from 9 to 1for ( i = 9; i>=1; i--) {// terminate loop when remainder is 0if ((i%5)==0)break;System.out.println("iteration number: " + i);}System.out.println("Loop completed.");System.out.println("Last iteration number" +i);}}