THE WORLD'S LARGEST WEB DEVELOPER SITE

Java continue Keyword

❮ Java Keywords


Example

Skip the iteration if the variable i is 4, but continue with the next iteration:

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  }
  System.out.println(i);
}
Run example »

Definition and Usage

The continue keyword is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration.


More Examples

Example

Use the continue keyword in a while loop

int i = 0;
while (i < 10) {
  if (i == 4) {
    i++;
    continue;
  }
  System.out.println(i);
  i++;
}
Run example »

Related Pages

Use the break keyword to break out of a loop.

Read more about for loops in our Java For Loops Tutorial.

Read more about while loops in our Java While Loops Tutorial.

Read more about break and continue in our Java Break Tutorial.


❮ Java Keywords