What is 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 of Break Statement in C :






  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 encounter's program exit's the loop and it will print the following output:

Break Statement in C, what is break in C


No comments:

Post a Comment

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