1The break statement "jumps out" of a loop.
2The continue statement "jumps over" one iteration in the loop.
1int i=0;
2while(i<10){
3 if(i%2==0){
4 i++;
5 continue;// If it's pair we return to the while
6 }
7 System.out.println(i);// If is not we print it.
8 i++;
9}
1// continue in java example
2import java.util.*;
3public class ContinueJavaExample
4{
5 public static void main(String[] args)
6 {
7 for(int a = 1; a <= 10; a++)
8 {
9 if(a % 2 != 0)
10 {
11 continue;
12 }
13 System.out.println(a + " ");
14 }
15 }
16}
1int i = 0;
2while (i < 10) {
3 if (i == 4) {
4 i++; //why do I need this line ?
5 continue;
6 }
7 System.out.println(i);
8 i++;
9}