Java Break Statement

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


 
Ads

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

Ads
Share on Google+Share on Google+

Java Break Statement

Posted on: November 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Java Break Statement  

Post your Comment


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

Ads

 

Ads