Break Statement In C Language
The
break ends the loop immediately when it is encountered.
When a break statement is encountered inside a loop, the
control directly comes out of loop and the loop gets terminated. It is used
with if statement, whenever used inside loop.
This can also be used in switch case control structure.
Whenever it is encountered in switch-case block.
Syntax:
break;
Fig: break statement in c |
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
for(num=100;num>=10;num--)
{
printf(“num:%d\n”,num);
if(num==99)
{
break;
}
}
printf(“out of loop”);
getch();
}
Output:
num:100
num:99
out of the loop
No comments:
Post a Comment