Open In App

Continue Statement in C

Last Updated : 03 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The continue statement in C is a jump statement used to skip the current iteration of a loop and continue with the next iteration. It is used inside loops (for, while, or do-while) along with the conditional statements to bypass the remaining statements in the current iteration and move on to the next iteration.

Example:

C
#include <stdio.h>

int main() {
  
    // Loop from 1 to 5
    for (int i = 1; i <= 5; i++) {
      
      	// Skip number 3
        if (i == 3)
            continue;
        printf("%d ", i);
    }

    return 0;
}

Output
1 2 4 5 

Explanation: The loop runs from 1 to 5 and print each number. We add the continue statement inside an if statement that checks if the number is 3 i.e. i == 3. If it is, continue is reached and printing of 3 is skipped.

Syntax of Continue in C

The syntax of continue is just the continue keyword placed wherever we want in the loop body.

C
continue;

The continue statement is used with conditional statements such as if-else to specify the condition for when to skip the iteration.

Working of C Continue

working of continue in c
Working of C continue in for Loop

Working of the Continue Statement:

  • The loop's execution starts after the loop condition is evaluated to be true.
  • The condition of the continue statement will be evaluated.
    • If the condition is false, the normal execution will continue.
    • If the condition is true, the program control will jump to the start of the loop and all the statements below the continue will be skipped.
  • Steps 1 and 2 will be repeated till the end of the loop.

Flowchart of Continue Statement

The flowchart of the continue can be constructed using the understanding of the continue we got from above.

flowchart of continue in c
Flowchart of the continue Statement in C

Examples of C continue

The below program illustrates how to use continue statements in our C programs

C
#include <stdio.h>

int main() {
    int n = 1;
    
    // Loop from 1 to 10
    while (n <= 10) {
      
      	// If the number is even, skip iteration
      	// to avoid printing it
        if (n % 2 == 0) {
            n++;
            continue; 
        }
        printf("%d ", n);
        n++;
    }

    return 0;
}

Output
1 3 5 7 9 

Explanation: The condition checks if the number n is even and when it's true it skips to the next iteration which prevents the print statement from executing as the print statement is below the continue so when the continue is executed (for even numbers), no printing is done.

Use continue in Nested Loops

The continue statement will only work in a single loop at a time. So, in the case of nested loops, we can use the continue statement to skip the current iteration of the inner loop when using nested loops.

C
#include <stdio.h>

int main() {

    // Outer loop with 3 iterations
    for (int i = 1; i <= 3; i++) {
      
        // Inner loop to print integer 1 to 4
        for (int j = 0; j <= 4; j++) {

            // Continue to skip printing number 3
            if (j == 3)
                continue;
            printf("%d ", j);
        }
        printf("\n");
    }
    return 0;
}

Output
0 1 2 4 
0 1 2 4 
0 1 2 4 

The continue skips the current iteration of the inner loop when it executes in the above program. As a result, the program is controlled by the inner loop update expression. In this way, 3 is never displayed in the output.

break vs continue

The primary difference between the break and continue statements is that by using break statement, we terminate the smallest enclosing loop (e.g, a while, do-while, for, or switch statement). On the other hand, by using the continue statement, we only skip the current iteration of the loop and execure the next iteration.


Next Article
Article Tags :

Similar Reads