Home Help Java B The break Keyword



The break Keyword
Posted on: October 6, 2010 at 12:00 AM
"break" is the java keyword used to terminate the program execution within a block of code that immediately comes to the currently enclosing block.

The break Keyword

     

"break" is the java keyword used to terminate the program execution within a block of code that immediately comes to the currently enclosing block. 

In other word we can say that break keyword is used to prematurely exit a for, while, or do loop or to mark the end of a case block in a switch statement. Also break keyword is used for terminate a loop. The break always exits an innermost enclosing while, for, do or switch statement.

The break statement is used to stop a loop for any reason and also the condition.

Examples: following example searches through an array for a particular value.

switch (n) {
case 0: System.out.println("ram"); 
break;
case 3: 
case 5: 
case 7: System.out.println(n + " good"); 
break;
case 2: System.out.println(n + " not"); 
case 4: 
case 6: 
case 8: System.out.println(n + " work hard"); 
break;
case 1: 
case 9: System.out.println(n + "ill"); 
break;
default: System.out.println("ram is work hard."); 
break;



Related Tags for The break Keyword:


More Tutorials from this section

Ask Questions?    Discuss: The break Keyword  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.