C continue statement

continue is a keyword in C language. It is used to bring the program control to the beginning of the loop.

Continue is also a loop control statement just like the break statement.

The continue statement skips the current iteration of the loop and continues with the next iteration.

As the name suggest the continue statement forces the loop to continue or execute the next iteration.

Syntax

//loop statements  
continue;  
//some lines of the code which is to be skipped  

Flowchart

C continue statement flowchart

Example

The continue statement is almost always used with the if...else statement.

#include<stdio.h>

int main() {
  int i = 1; //initializing a local variable       
  //starting a loop from 1 to 10    
  for (i = 1; i <= 10; i++) {
    if (i == 5) { //if value of i is equal to 5, it will continue the loop    
      continue; /* skip the iteration */
    }
    printf("%d \n", i);
  } //end of for loop    
  return 0;
}
C continue statement example – output

As you can see, 5 is not printed on the console because we used continue statement at i==5.

C continue statement with inner loop

#include<stdio.h>

int main() {
  int i = 1, j = 1; //initializing a local variable    
  for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 3; j++) {
      if (i == 2 && j == 2) {
        continue; //will continue loop of j only    
      }
      printf("%d %d\n", i, j);
    }
  } //end of for loop    
  return 0;
}
C continue statement with inner loop example – output

As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.