Home Java Java-break-example Java Break loop



Java Break loop
Posted on: November 11, 2008 at 12:00 AM
Java contains its own Branching Category in which it has two keywords of opposite nature, break and continue respectively.

Java Break loop

     

Java contains its own Branching Category in which it has two keywords of opposite nature, break and continue respectively. In the following example break statement is  used to break two looping statements do-while & for loop respectively. In both loops, break statements are set with if conditions. This java keyword acts as terminator for loops in computer programs, they are used in two forms labeled and unlabeled & in both forms it works efficiently in terminating the loops.

 

 

 

 

 

Break Loop Example in Java

public class Java_Break_loop {
public static void main(String args[]) {

boolean value = true, trueValue = true;x
String str = "Heavenly bodies";
int i = 9, modulo = str.length(); // here due to odd integer, loop forming is finite in nature 

do
{
i++;
modulo--;
System.out.println("welcome to roseindia.net");

if((modulo == i) && (value == true)) // if these if and break statementments are commented then 
break; //this do while loop will become an infinite loop.

}while(value);




System.out.println("\n\nvalue of " + "modulo = " + modulo + " & " + "i = " + i);


System.out.print("\nSwitched : "); 
boolean bool = true;
switch(str.length() - 13) {
case 0 : System.out.println("matrix revolution");
break;

case 1 : System.out.println("body is nothing without mind");
break;

case 2 : System.out.print("Heavenly bodies\n\n");
break;

default : System.out.println("varied environment");
break;


}
}

Download the example


Related Tags for Java Break loop:
javacooploopsiosedwordloopbranchbranchingkeystatekeywordsaisetoopingifconditionforexamplekeywordwithsitestatementnatwhiletobreakcontainsexamposloopingwordsboteilitcategoryusepecontinueinasstaconditionsmntpsososicaosiosjoopsesspecempimeppstatementscatdoxawhichxampsrespectspespatpinkishallivmplgofolloweaandarstatrdswingvatwssrdthcondavstchipleplndonolo


More Tutorials from this section

Ask Questions?    Discuss: Java Break loop  

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.