Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

 The continue statement

C Programming Language continue statement

The continue statement forces loop to skip statements written after it & continue next execution of the loop.

Syntax

continue;

Note

If the continue statement is encountered in the for loop, program control jumps directly to the update expression.
If the continue statement is encountered in the while & do-while loops, program control jumps directly to the condition.

C Programming Language continue statement Working

Case 1 – Using continue statement in for loop.

Example

#include<stdio.h>
int main()
{
    int i;
	
    for(i=11;i<=20;i++)
    {
        if(i==14)
            continue;
		    
        printf("\n %d",i);
    }
    printf("\n After for loop");
    return 0;
}

Output

 11
 12
 13
 15
 16
 17
 18
 19
 20
 After for loop

In the above program, 14 is not printed.

Case 2 – Using continue statement in while loop

Example

#include<stdio.h>
int main()
{
    int i;
    i=11;
    while(i<=20)
    {
        if(i==14)
            continue;
		    
        printf("\n %d",i);
        i++;
    }	
    printf("\n After for loop");
    return 0;
}

Output

 11
 12
 13

After printing 13, while loop executes infinitely because condition always becomes true.

Case 3 – Using continue statement in do-while

Example

#include<stdio.h>
int main()
{
    int i;
    i=11;
    do
    {
        if(i==14)
            continue;
		    
         printf("\n %d",i);
         i++;
    }while(i<=20);
		
    printf("\n After for loop");
    return 0;
}

Output

 11
 12
 13

After printing 13, do-while loop executes infinitely because condition always becomes true.

 

Leave a reply