Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0062 continue

continue statement forces an early iteration of a loop. In while and do-while loops, a continue statement causes control to be transferred to the conditional expression that controls the loop. In a for loop, control goes first to the iteration portion of the for statement and then to the conditional expression. The following code shows how to use a continue statement. public class Main { public static void main(String[] argv) { for (int i = 0; i < 10; i++) { System.out.print(i + " "); if (i % 2 == 0) continue; System.out.println(""); } } } The code above generates the following result. 0 1 2 3 4 5 6 7 8 9