Continue statements

Continue statement in C programming language

Continue statement in C programming language

C program continue statement

We will get to know the uses of Continue statement in C programming language in this tutorial (using for loop and while loop) – it controls the flow of control of loops  in C language

Description

Continue is a keyword in the C language (some time called as a statement because ending with the semicolon)which is used to control the flow of loops.

Typically, this can be used inside of the while and for loop.

The continue statement provides the option to skip the current iteration(skip some steps) of the flow of control to the following loops until the flow of control exits the loops.

The syntax of the continue

continue;

Flow diagram of continue

Continue statement in Python

 

How continue  works in C – control flow for loop

the control flow of for loop

 

How to continue statement works  in C – control flow – while loop

the control flow of continue in while loop

continue statement in for loop

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i;
    for(i=1; i<=10; i++)
    {
        if(i==5){
            printf("Skipped this value :%d\n",i);
            continue;
        }
        printf("%d\n",i);
    }
    printf("End of loop\n");
    getch();
    return 0;
}

 

When the above code is compiled and executed, it will produce the following results

1
2
3
4
skipped value :5
6
7
8
9
10
End of loop

 

When this program is executed, number 5 skipped by continue statement in for loop of C

Program 2

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int num;
    int sum=0;
    int i,n;
    printf("Enter any number \n");
    scanf("%d",&n);

    for(i=1; i<=n; i++){
            printf("Enter Number :%d\n",i);
            scanf("%d",&num);
            if(num==20){
                continue;
            }
           sum=sum+num;
        }
        printf("Total value is :%d\n",sum);
    printf("End of program");
    getch();
    return 0;
}


 

When the above code is compiled and executed, it will produce the following results

Enter any number 5 
Enter number :1 
10 
Enter number :2 
20
Enter number :3 
30 
Enter number :4 
40 
Enter number :5 
50
Total value is :130 
End of program

Number 20 skipped by continue statements from the addition

Continue in while loop in C

Program 3

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i=1;
    while(i<=10){
        if(i==6){
            printf("Skipped value :%d\n",i);
            i++;
               continue;
        }
        printf("value %d\n",i);
        i++;
    }
    printf("End of loop\n");
    getch();
    return 0;
}

 

When the above code is compiled and executed, it will produce the following results

value 1
value 2
value 3
value 4
value 5
Skipped value :6
value 7
value 8
value 9
value 10
End of loop

 

When this program is executed, number 6 skipped the continue statement in for loop

Program 4

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int num;
    int sum=0;
    int i,n;
    printf("Enter any number \n");
    scanf("%d",&n);
    i=1;
    while(i<=n){
            printf("Enter Number :%d\n",i);
            scanf("%d",&num);
            if(num==25){
                continue;
                ++i;
            }
           sum=sum+num;
           ++i;
        }
        printf("Total value is :%d\n",sum);
    printf("End of program\n");
    getch();
    return 0;
}

 

When the above code is compiled and executed, it will produce the following results

Enter any  number
5
Enter number :1
10
Enter number :2
15
Enter number :3
20
Enter number :4
25
Enter number :5
30
Total value is :110
End of program

When this program is executed, number 25 is skipped from calculating total by continue statement in for loop

 

Suggested for you

Break statement in Python

break keyword in  Java Language

Keyword in Python language

Continue statements in Python

Continue statements in C language

Keyword in C language

Keyword in Java language

for loop in C language

While loop in C language

 

The continue keyword in Java programming language
Continue statement in Python programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 weeks ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

2 weeks ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

3 weeks ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago