Simple example for break and continue in java
/**
*
*/
package com.belazy.generics;
/**
* @author belazy
*
* How break and continue works in java
*
*/
public class ControlStructures {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] numbers = {1,2,3,4,5,6,7,8,9};
System.out.println("\n--- break ------------ ");
for(int number :numbers){
if(number ==5)
break;
System.out.print(number +" ");
}
System.out.println("\n--- continue ------------ ");
for(int number :numbers){
if(number ==5)
continue;
System.out.print(number +" ");
}
}
}
Output
--- break ------------
1 2 3 4
--- continue ------------
1 2 3 4 6 7 8 9
No comments:
Post a Comment
Your feedback may help others !!!