Continue Keyword in C

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

The continue keyword in C doesn’t terminate the loop, but when continue keyword occurs then control of the program jumped to the ending of the loop and later to the beginning of the loop. Due to this the remaining statements of loop after the continue keyword is skipped.

Syntax:- continue

Table Of Contents


Use of continue statement in C

Using continue keyword inside while loop

 #include<stdio.h>
 int main()
 {
   int i=0;
   while(i<5)
   {
     i++;
     if(i==3) continue;
     printf("%d\t",i);
   }
   return 0;
 }

Output:-

1 2 4 5

In this program, when the value of the variable i becomes 3 then the continue statement is executed. Due to the continue statement, the remaining statement of the while loop is skipped.

Using continue keyword inside for loop

 #include<stdio.h>
 int main()
 {
   for(int i=1; i<5; i++)
   {
     if(i==3) continue;
     printf("%d\t",i);
   }
   return 0;
 }

Output:-

1 2 4

continue statement

Continue keyword in C inside nested loops

The continue keyword of the inner loop only skip statements of the inner loop, it doesn’t affect outer loop statements.

 #include<stdio.h>
 int main()
 {
   for(int i=1; i<=3; i++)
   {
     for(int j=1; j<=3; j++)
     {
       if(i==2) continue;
       printf("i=%d \t j=%d\n",i, j);
     }
     printf("Outer for loop, i=%d\n",i);
   }
   return 0;
 }

Output:-

i=1 j=1
i=1 j=2
i=1 j=3
Outer for loop, i=1
Outer for loop, i=2
i=3 j=1
i=3 j=2
i=3 j=3
Outer for loop, i=3

In below program, if the value of any variable either i and j is even then continue skip the remaining statements of the inner loop.

 #include<stdio.h>
 int main()
 {
   for(int i=1; i<5; i++)
   {
     for(int j=1; j<5; j++)
     {
       if(i%2==0 || j%2==0) continue;
       printf("%d\t%d\n",i,j);
     }
   }
   return 0;
 }

Output:-

1 1
1 3
3 1
3 3

The rule for continue statement

The continue keyword, only used within loops.

 #include<stdio.h>
 int main()
 {
   printf("Hello");
   continue;
   printf("Hi");
   return 0;
 }

Difference between Break and Continue

break continue
It helps to make an early exit from the block where it appears. It helps in avoiding the remaining statements in a current iteration of the loop and continuing with the next iteration.
It can be used in all control statements including switch-case statements. It can be only used in loop statements, can’t with switch-case statements.
It can be executed only once per loop. It can execute more than one time in a loop.

Programs using Continue in C

Program:- Display odd number in a given range

 #include<stdio.h>
 int main()
 {
   int i=0, n;
   printf("Enter n value: ");
   scanf("%d",&n);
   while(i<=n)
   {
     i++;
     if(i%2==0) continue;
     printf("%d\t",i);
   }
   return 0;
 }

Output:-

1 3 5 7 9 11 13 15

Program:- Find the sum of positive numbers in a given set of 5 numbers. The program should accept input values from the user.

 #include<stdio.h>
 int main()
 {
   int sum=0;
   for(int n, i=0; i<5; i++)
   {
     printf("Enter a number: ");
     scanf("%d",&n);
     if(n<0) continue;
     sum += n;
   }
   printf("Sum = %d",sum);
   return 0;
 }

Output:-

Enter a number: 5
Enter a number: -10
Enter a number: 20
Enter a number: -8
Enter a number: 0
Sum = 25

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Reply