Break Statement

When ever we want to exit from the loop or from a function like main()/user defined function we use Break statement.It comes out of the loop and goes to the next line of the program.It exits only from the loop in which it has been written.
Ex:
To print values from 1-n with in 100 using break statement.

#include<estdio.h>
main()
{
int i,n;
printf(“Enter any number between 1-100\n”);
scanf(“%d”,&n);
for(i=1;i<=100;i++)
{
if(i!=n+1)
{
printf(“I am in for loop with value %d\n”,i);
}
else
{
break;
}
}
printf(“Out of for loop\n”);
}

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post