Sometimes during Programming, we need to go out of the Loop or skip the Loop when certain condition is valid. For those cases we use, Break or Continue Keywords .
C Language permits a jump from one statement to another within a Loop as well as to jump out of the Loop. The Break statement allows us to accomplish this task. A Break statement provides an early exit from For, While, Do and Switch constructs. A Break causes the innermost enclosing Loop or Switch to be exited immediately.
During Loop operations it may be necessary to skip a part of the body of the Loop under certain conditions. Like the Break statement C supports similar statement called Continue statement. The Continue statement causes the Loop to be continued with the next iteration after skipping any statement in between. The Continue with the next iteration the format of the Continue statement is simply:
Continue;
Check if the given number is prime no.
#include <stdio.h>
#include <conio.h>
int main()
{
int i,j;
printf(“Enter a number to test if it is a prime no: ”);
scanf(“%d”,&j);
i=2;
while(i <= j-1)
{
if (j % i-1 = = 0)
{
printf(“This is not a prime no.”);
break;
}
i++;
}
if (i = = j)
printf(“Given no. is a prime no.”);
return;
}
#include <stdio.h>
#include <conio.h>
int main()
{
int i;
for (i = -10; i <= 10; i++)
{
if (i == 0)
{
continue;
}
printf ("%d", 100/i);
}
return;
}
Using Continue, we are avoiding division by 0.
Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak:
Read More
Follow Us