Summary: The continue statement skips remaining statements in the loop body where it appears.
The continue statement, like break, interrupts the normal flow of execution in a loop body. But instead of ending the loop, continue skips all following statements in the loop body and triggers the next iteration of the loop. This effect can be useful within complex loops, in which you might wish to skip to the next loop iteration from various locations.
The CONT.C program shows how continue works. It increments the count variable, counting from 0 through 9, but stops printing the value of count when that value exceeds 3.
/* CONT.C: Demonstrate continue statement. */
#include <stdio.h>
main()
{
int count;
for( count = 0; count < 10; count = count + 1 )
{
if( count > 3 )
continue;
printf( "count = %d\n", count );
}
printf( "Done!\n" );
}
Here's the output from CONT.C:
count = 0
count = 1
count = 2
count = 3
Done!
The continue statement occurs within the body of the for loop. When the value of count exceeds 3, the continue skips the rest of the loop body—a statement that calls printf—and causes the next iteration of the loop.