google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Break Statement in Java

Break Statement in Java

0

Break Statement is used to break a Loop and Statement immediately after the break executed. We use the break keyword to apply Break Statement.

Break Statement is generally used in two types.

  1. When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
  2. It can be used to terminate a case in the switch statement.

  If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax

The syntax for a break statement in Java is as follows −

    

break;


Example:


import java.io.*;
 
class abc
{
public static void main(String args[])
{


   /* local variable definition */
   int a = 10;

   /* while loop execution */
   while( a < 20 ) {
   
      System.out.println("value of a=", a);
      a++;
      if( a > 15) {
         /* terminate the loop using break statement */
         break;
      }
   }
 
}

}

Output:

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15

Flow Chart:



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top