The continue Statement


Syntax

continue;

Notes

The continue statement may only occur within one of the following statements:

The continue statement causes the flow of execution to be transferred to the loop continuation portion of the enclosing loop statement. Unlike the break statement, the continue statement does not cause automatic termination of a loop; rather, it causes the loop condition to be re-tested and the flow of execution is then determined as a result of the test.

Examples

The following example adds the numbers 0-9 excluding 5.

int j=0;
for (int i=0; i<10; i++)
 {
  if (i==5) continue;
  j += i;
 }
 
 // Loop adds numbers 0 - 9 excluding 5, upon exit i==10, j==40.

The following example also adds the numbers 0-9 excluding 5.

int i=0;
int j=0;
while(i<10)
 {
  if (i==5) continue;
  j += i;
  i++;
 }
 
 // Loop adds numbers 0 - 9 excluding 5, upon exit i==10, j==40.