Home Java Java-break-example Java Break Statement



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

Related Tags for Java Break Statement:
javacoopcomidesedloopbranchbranchingrmistateidooprogramstatementnattobreakrameitterminatecategoryuseinrmstamntsidsidemincaminjesemmeprostatementscatstermatkisgoeastatcodcodevassthavstchiprminamindodeomogro


More Tutorials from this section

Ask Questions?    Discuss: Java Break Statement  

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.