WEB DEVELOPER SITE
PHP7
 

Break statement in java



Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.

Syntax

The syntax of a break is a single statement inside any loop −

break;

Example

public class Test {

   public static void main(String args[]) {
      int [] numbers = {20, 40, 60, 80, 100};

      for(int x : numbers ) {
         if( x == 10) {
            break;
         }
         System.out.print( x );
         System.out.print("\n");
      }
   }
}
Run Example»