continue Statement
A continue
statement is used in a loop created by a while
or do
statement to skip the remaining statements in the loop. When the continue
statement is encountered, control jumps back to the top (while
) or bottom (do
) of the loop. There, the expression is immediately evaluated again. If the expression is still true
, the loop’s statement or block is executed again.
Here’s a loop that counts from 1 to 20, but skips the number 12:
int number = 0;
while (number < 20)
{
number++;
if (number == 12)
continue;
System.out.print(number + “ “);
}
This loop produces the following output in the console window:
1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20