Continue Statement in C Programming





In C programming, the continue statement is used within loops to skip the rest of the current iteration and proceed to the next iteration of the loop.

Definition:

The continue statement is used to jump to the next iteration of a loop, bypassing the remaining code inside the current iteration block.

Syntax:

    continue;
    

Explanation:

When a continue statement is encountered within a loop, the program skips the remaining code inside the current iteration block and moves to the next iteration of the loop. This can be useful for cases where you want to skip certain iterations based on a condition.

Example:

#include <stdio.h>

int main() {
    int i;
    for (i = 1; i <= 5; i++) {
        if (i == 3) {
            continue; // Skip iteration when i is 3
        }
        printf("Iteration %d\n", i);
    }
    return 0;
}
    
Output:
Iteration 1
Iteration 2
Iteration 4
Iteration 5

In this example, the program will print "Iteration 1" and "Iteration 2," but it will skip the iteration when i is 3 due to the continue statement, and then it will continue with "Iteration 4" and "Iteration 5."