Java Break Statement

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.

'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

Ads

Ads