Break and Continue - C Statement

C examples for Statement:break

Introduction

break and continue are two jump statements that can be used inside loops.

The break statement ends the loop.

The continue statement skips the rest of the current iteration and continues at the next iteration.

Demo Code

#include <stdio.h>
int main(void) {

    int i;/*from ww  w  .  j a v a2s. co m*/
    for (i = 0; i < 10; i++)
    {
      if (i == 2)
         continue;   /* start next iteration */
      else if (i == 5)
         break; /* end loop */
      printf("%d\n", i);
    }
}

Result


Related Tutorials