Break and Continue statements


break


break statements are useful when we want to break your loop or we want to exit the loop when we reach a specific condition.

if the break statement is executed then the control moves on the next statement after the loop

we can say that the beak statement work as a forward jump in your program.



example:
//Break

#include <stdio.h>
int main ()
{
int a;
while (1)
{
printf("enter the number:");
scanf("%d", &a);
if ( a == 0 )
break;
}
return 0;
}

This program runs until we not provide 0 as input


continue


continue statement is used when we want to skip some part of that particular iteration or iteration and we want to execute the next iteration of the loop. when the continue statement is executed the control jump on the next statement in the loop.

we can say that the continue statement is working like a backward jump in your program.



example:
//Continue statement

#include <stdio.h>
int main ()
{
int a,sum = 0;
for (a = 0; a<10; a++)
{
if ( a % 2 == 0 )
continue;
sum = sum + a;
}
printf("sum = %d",sum);
return 0;
}




this program sum all the odd number and skip the all even number.