The Continue Statement in C Programming With Example Program

Unlike break statement, Continue statement is used to jump the control out of the loop, it is sometimes required to skip some part of the loop and to continue the execution with next loop iteration.

Continue statement used inside the loop helps to bypass the section of a loop and passes the control to the beginning of the loop to continue the execution with the next loop iteration.

The Syntax of Continue statement

continue;

Let us see the program given below to know the working of the continue statement.

Write a program to print first 20 natural numbers skipping the numbers divisible by 5

/* Program to print first 20 natural numbers skipping the numbers divisible by 5 */

#include <stdio.h>

main( )

{

int i;

for (i=1;i<=20;++i)

{

if ((i % 5) == 0)

continue;

printf(“%d ”,i);

}

}

OUTPUT

1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19

Here, the printf statement is bypassed each time when value stored in i is divisible by 5.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: