Java Program Showing Use of Break Statement…

Break:

 B

reak is used inside a loop to come out of it.


Example:

class BreakLoop
{
  public static void main(String args [])
  {
    for(int i=0;i<100;i++)
    {
      if(i==10)
      break;
      System.out.println(“i : ” + i);
    }
    System.out.println(“Loop Completed”);
  }
}
Output:
D:java >java BreakLoop
i : 0
i : 1
i : 2
i : 3
i : 4
i : 5
i : 6
i : 7
i : 8
i : 9
Loop Completed

Add Comment