Jul 14, 2020

Break statement in C

Break statement is very useful to exit from any loop  such as for loop, while loop and do while loop. When the break statement is encountered in the loop then the loop will stop running the statements and immediately exit from the loop.




Syntax:





Example program of break statement:


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

 for(i=1;i<=10;i++)
 {
     if(i==5)
     {
      break;
     }
     else
     {
     printf("%d ",i);
     }
 }
}


In above program we have used break statement. When break statement encountered program will exit the loop and it will print the following output:



Share This:    Facebook Twitter

0 Comments:

Post a Comment

If you have any doubts, please discuss here...