break statement in loops in C language by R4R Team

Use of Break in loop:

-We use break statement to break the loop at certain point.

Syntax-
for(statement,statement,statement)
{
break;
}

Example-

int a;
scanf("%d",&a);
for(i=0;i< 1000;i++)
{
if(i==a)
break;
}

-It will break the loop when value of i is become the input value.


program-

#include< stdio.h>
int main()
{
int range,i;
printf("Enter number to run loop\n");
scanf("%d",&range);
for(i=0;i< 1000;i++)
{
printf("%d\n",i);
if(i==range)
{
break;
}
}
}


output-

Enter number to run loop
5
0
1
2
3
4
5




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!