Easy Tutorial
❮ C Exercise Example3 C Function Getchar ❯

C break Statement

C Loops

In C language, the break statement has the following two uses:

If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax

The syntax for the break statement in C language is:

break;

Flowchart

Example

Example

#include <stdio.h>

int main ()
{
   /* Local variable definition */
   int a = 10;

   /* while loop execution */
   while( a < 20 )
   {
      printf("Value of a: %d\n", a);
      a++;
      if( a > 15)
      {
         /* Terminate the loop using break statement */
         break;
      }
   }

   return 0;
}

When the above code is compiled and executed, it produces the following result:

Value of a: 10
Value of a: 11
Value of a: 12
Value of a: 13
Value of a: 14
Value of a: 15

C Loops

❮ C Exercise Example3 C Function Getchar ❯