/* */ Click to Join Live Class with Shankar sir Call 9798158723

break statement in C ?


The break statement in C programming has the following two usages −
When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
It can be used to terminate a case in the switch statement .

Syntax:-

for(.....)
{
......
if(error1)
break;
.....
} break;

Note: "When break statement is executed, the control comes out of the switch statement."

Q.) W.A.P to print 1 to 4.
 #include<stdio.h>
 #include<conio.h>
 void main()
 {
 int   i;
 for(i=1;  i<=10;  i++)
 {
 if(i==5)
 {
 break;
 }
 printf(“%d\n”,i);
 }
 getch();
 }
Output
1
2
3
4