Home Java Java-break-example Java Break command



Java Break command
Posted on: November 11, 2008 at 12:00 AM
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

Related Tags for Java Break command:
javacprogrammingoopcomideprocessloopscontrolsedloopcommandbranchlabelbranchingrmistatereturnlineidooprocessingprogrammerlikepingforwherewithworksiteprogramstatementnatwhiletobreakramposprogrammerssseloopingprocssieilitlscategorycommaliusemanfromcecontinueinrmpassasstamntoutpstrminososicaminosiosjoopsesemcommonpimeproppouterstatementscatwhichsurntermsodelginessatpinkisgoeaandstatbreakingbeginningwidvassrocriringthavbeginstchiababelatietcetclsoprocesprmostminamindonlyonomogrolonl


More Tutorials from this section

Ask Questions?    Discuss: Java Break command  

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.