Java Continue Statement
Java Continue Statement
The continue statement is used in loop control structure when you need to jump to the next iteration of
the loop immediately. It can be used with for loop or while loop.
The Java continue statement is used to continue the loop. It continues the current flow of the program
and skips the remaining code at the specified condition. In case of an inner loop, it continues the inner
loop only.
Output:
1
2
3
4
6
7
8
9
10
ASR 1
public class ContinueExample2 {
public static void main(String[] args) {
//outer loop
for(int i=1;i<=3;i++){
//inner loop
for(int j=1;j<=3;j++){
if(i==2&&j==2){
//using continue statement inside inner loop
continue;
}
System.out.println(i+" "+j);
}
}
}
}
Output:
1 1
1 2
1 3
2 1
2 3
3 1
3 2
3 3
Example:
ASR 2
System.out.println(i+" "+j);
}
}
}
}
Output:
1 1
1 2
1 3
2 1
3 1
3 2
3 3
Output:
1
2
3
4
6
7
8
9
ASR 3
10
Output:
1
2
3
4
6
7
8
9
10
ASR 4