C break statement


The break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. The break statement in C can be used in the following two scenarios:

  1. With switch case
  2. With loop

Syntax:



  1. //loop or switch case   
  2. break


Example



  1. #include<stdio.h>  
  2. #include<stdlib.h>  
  3. void main ()  
  4. {  
  5.     int i;  
  6.     for(i = 0; i<10; i++)  
  7.     {  
  8.         printf("%d ",i);  
  9.         if(i == 5)  
  10.         break;  
  11.     }  
  12.     printf("came outside of loop i = %d",i);  
  13.       
  14. }  

Output

0 1 2 3 4 5 came outside of loop i = 5



Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya