Continue (Java)
Appearance
The continue keyword works in Java keywords in the same way that it does in the C Programming Language and also C++. When used inside of while and for loops where it will skip the remaining instructions in the loop and begin on the next iteration in the loop.
The following prints only even numbers between and including 0 and 10
for(int i=0; i<=10; i++){ //skips the print statement if i is not even if(i % 2 != 0) continue; //prints the integer "i" System.out.println(i); }
The result of this loop is
0
2
4
6
8
10