Break Statement

The break statement terminates the execution of the nearest enclosing do, for, switch or while statement in which it appears.The break statement is used inside loops or switch statement and break statement breaks the loop one by one.

The break statement in C language can be used in two ways

  • With switch case
  • With loop

Syntax of break statement

//loop or switch case
break;

Break Statement with while loop

Example to use the break statement with while loop

#include<stdio.h>  
void main ()  
{  
    int i = 0;  
    while(1)  
    {  
        printf("%d  ",i);  
        i++;  
        if(i == 10)  
        break;   
    }  
    
}

Output

0 1 2 3 4 5 6 7 8 9

break statement with for loop

Example to use the break statement with a for loop

#include <stdio.h>
int main()
{
      int var;
      for (var =100; var>=10; var --)
      {
           printf("var: %d\n", var);
           if (var==99)
           {
               break;
           }
      }
    
     return 0;
}

Output

var: 100
var: 99

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews