'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"); } } |
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.
Ask Questions? Discuss: Java Break Statement
Post your Comment