Home Java Java-break-example Java Break loop

Related Tutorials


 
 

Share on Google+Share on Google+

Java Break loop

Advertisement
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


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

Discuss: Java Break loop  

Post your Comment


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