How to interrupt a Loop in C Language

‮w//:sptth‬ww.lautturi.com
How to interrupt a Loop in C Language

In C language, you can use continue or break to interrupt the loop.

Continue will stop the current loop and continue the next loop.
Break will terminate the entire loop.

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  }
  printf("%d ",i);
}

//output:
//0 1 2 3 5 6 7 8 9

printf("\n");

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

//output:
//0 1 2 3
Created Time:2017-08-28 21:52:49  Author:lautturi