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

 
 

Share on Google+Share on Google+

Java Break Statement

Advertisement
'break' statement comes under the branching statements category of java. It is used to terminate the loop coded inside the program.

Java Break Statement

     

'break' statement comes under the branching statements category of java. It is used to terminate the loop coded inside the program. 
Example below demonstrates the working of break statement inside the program. This example is of unlabeled break statement in java.
In the program break statement is terminating the for loop when the if condition defined under the for loop is satisfied.

 

 

 

 

 

Syntax for Break Statement in Java

public class Java_Break_Statement {
public static void main (String args[]) {
String str[] = {" * ", " * ", " * ","roseindia", ".net"};
boolean rachel = false;
int weisz;
String strv = "roseindia";

for (weisz = 0; weisz < str.length; weisz++) {
if(str[weisz] == strv) {
rachel = true;
break;

System.out.print("!*");
}


System.out.print("!");

if(rachel) 
System.out.println("\nCompany " + strv + " discovered in string dimension at index : " + weisz);

else 
System.out.println("Company " + strv + " undiscovered");


}
}


Download the code

Advertisements

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 Statement  

Post your Comment


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