Break Statement in c

Break statement is used to exit the loop. we can use break statement in for,do ,while , switch and may other looping statements .when the controller encounters break; ,the controller skips the further code and goes to next statement outside the loop.

syntax:

break;

flowchart:

break keyword in c

Working of break statement:

how break keyword is used in c

*example:*

int main()
{
int i,sum,x;
for(i=1;i<=5;i++)
{
printf(" enter %dst number",i);
scanf("%d",&x);
if(x<0)
{
break;
}
sum += x;
}
printf("%d",sum-1);
}
this example is for the addition of any five numbers. but if the user gives any negative number the loop will be stopped using the break state