Java Reference
In-Depth Information
String [] students ={"James", "Anil", "Tom", "Aman"};
for( String name : students ) {
System.out.print( name );
System.out.print(" ");
}
}
}
Result:
10 20 30 40 50
James Anil Tom Aman
break Keyword
Java provides break keyword which is used to terminate the entire loop. This keyword can
be used inside a loop or switch statement to terminate that lop or switch.
Keep in mind that in case of nested loops, break keyword only terminates the execution of
innermost loop transferring the execution to the first statement following that loop.
Example:
public class Demo {
public static void main(String args[]) {
int [] values = {10, 20, 30, 40, 50};
for(int a : values) {
if( a == 40 ) {
break;
}
Search WWH ::




Custom Search