Previous Next

C Break and Continue

Break Statement

The break statement is utilized to escape the loop within which it occurs. The break statement is applied within loops or switch statements within C programming.

Example:

#include <stdio.h>

int main () {
  int i;
  for (i = 0; i < 10; i++) {
    if (i == 6) {
      break;
    }
    printf ("%d", i);
  }
  return 0;
}

Output:

0 1 2 3 4 5

Continue Statement

The continue statement skips the current iteration of the loop and moves to the next iteration.

Example:

#include <stdio.h>

int main () {
  int i,j;
  for (i = 1; i <= 2; i++)
  {
    for (j = 1; j <= 2; j++) {
      if (i == j)
       continue;
      printf ("%d%d", i,j);
    }
  }
  return 0;
}

Output:

1 2 2 1
Previous Next