continue Statement

Purpose:

When executed in a while, for, or do-while structure, skips the remaining statements in the body of that structure, and proceeds with the next iteration of the loop.

Mechanics:

continue;

Example:

for(int i=0; i<10; i++) {
if (numA == 5) {
continue; // if the integer numA, is 5, continue with the next iteration of the loop.
}
/* other Java statement */
}

Usage:

  • In while and do-while structure, execution continues by evaluating the loop-continuation condition.
  • In the for structure, execution continues by incrementing the counter and then evaluating the loop continuation condition.

Restrictions:

In most cases, a while structure can be used to represent a for structure. However, if the counter variable in a while loop is incremented after a continue statement, the while loop will not execute in the same manner as the for loop.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu