Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Help Java B The break Keyword

Related Tutorials


 
 

Share on Google+Share on Google+

The break Keyword

Advertisement
"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;



Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 6, 2010

Related Tutorials

Discuss: The break Keyword  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com