continue statement

When continue encountered inside any loop, control automatically passes to the beginning of the loop.
It is used when we want to take the control to the beginning of the loop, bypassing the statement inside the loop.

Write a program to  print 1 to 10 numbers on display but numbers divisible by 2 should not be display.  We can see in below C program the printf() statement is bypassing inside the loop whenever variable becomes divisible by 2..

#include<stdio.h>
int main()
{

int count;for (count = 1; count <= 10; count++)

{

if (count%2 == 0)

{

continue;

}

printf(“%d \t”,count);

}

}

When continue encountered inside any loop, control automatically passes to the beginning of the loop, the output is :-
$  ./a.out
1    3    5    7    9

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.