<

Java break Tutorial

Break statement are two types labeled and unlabeled.

Label transfer the control to the start of the code..


Java Break Statement Example


public class BreakDemo
{
   public static void main(String[] args)
   {
      for (int i = 1; i <= 10; i++)
      {
         if (i == 5)
         {
            break;    // terminate loop if i is 5
         }

         System.out.print(i + " ");
      }

      System.out.println("Loop is over.");
   }
}

OUTPUT:
1 2 3 4 Loop is over















© copyright 2017-2022 Completedone pvt ltd.