Home Java Java-break-example Java Break command
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java Break command

Advertisement
Java Break command is commonly used in terminating looping statements. break command comes under the Java branching statements category. In programming it is widely used by programmers for breaking loops like 'for', 'while' etc.

Java Break command

     


Java Break command is commonly used in terminating looping statements. break command comes under the Java branching statements category. In programming it is widely used by programmers for breaking loops like 'for', 'while' etc. . break is often used with label continue, which also comes under Java branching statements category but works just opposite to break. break brings the program control out of the outermost loop whereas continue returns the program control from the line at which the continue label is passed at the beginning of the outermost loop for re-processing. 

 

 

 

 

Break Command in Java Example

import javax.swing.*;
public class Java_Break_command {
public static void main(String args[]) {

String str = "roseindia", choice = "";
boolean self = true;

way:
do{
choice = JOptionPane.showInputDialog(null, "\tEnter string", "String Input First chance", 1); 
if (choice.equals(str)) {

JOptionPane.showMessageDialog(null, "Rigth entry\n\t\tCongratulations" , "\t\t\t\t\t\tHurray....", 2); 
break;
}

else if(!(choice.equals(str))){
JOptionPane.showMessageDialog(null, "wrong entry\n\t\t\ttry again", "\t\t opps...", 0); 
choice = JOptionPane.showInputDialog(null, "\tEnter string", "String Input Last Chance", 1); 

if (choice.equals(str)) {
JOptionPane.showMessageDialog(null, "Rigth entry\n\t\tCongratulations" , "\t\t\t\t\t\tHurray....", 2); 
break;
}

else if(!(choice.equals(str))) {
JOptionPane.showMessageDialog(null, "get the rigth entry\n and then restart the program", " oops Session time out", 0);
break;
}

}

}while(self);


}

Download the code

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: November 11, 2008

Related Tutorials

Ask Questions?    Discuss: Java Break command  

Post your Comment


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