EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Continue Statement in C

Home » Software Development » Software Development Tutorials » C Programming Tutorial » Continue Statement in C

Continue Statement in C

Introduction to Continue Statement in C

Here, we are going to learn about the continue statement in C. This statement is majorly used in the case of iterators or in case of looping. This statement as the name already suggests, makes sure that the code continues running after a particular statement is executed. It is used in the same way as the break statement, but the break statement would stop the execution of the loop or series of statements, but the continue statement in return would continue the execution of the code.

Below is the syntax for the continue statement in C.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

continue;

As already mentioned, the continue statement is used in loops. So the only syntax for the statement would be like above.

Flow Chart:

We can understand it better through a flow chart, let’s see it below.

FlowChart of continue statement

Explanation

  • As already known, any loop starts with a condition, and there would be two scenarios for it. One is the statement that has to be executed when a condition is true and others when it is false.
  • When a condition is false, it is going to obviously exit the loop.
  • And when a condition is true, and have our continue statement, the iterator again goes back to the condition and the above process continues.
  • If the condition does not have that continue statement, then the code below is executed.

Now let’s move on to use this statement in our program and see how it works.

Examples

We will have a look at 3 examples on how to continue statement can be used in C language.

Popular Course in this category
C Programming Training (3 Courses, 5 Project)3 Online Courses | 5 Hands-on Projects | 34+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,617 ratings)
Course Price

View Course

Related Courses
C++ Training (4 Courses, 5 Projects, 4 Quizzes)Java Training (40 Courses, 29 Projects, 4 Quizzes)

Example #1

Finding odd numbers from o to 20.

Code:

#include <stdio.h>
int main()
{
int i;
for(i=0;i<20;i++)
{
if(i%2==0)
{
continue;
}
printf("%d ",i);
}
}

Output:

Continue Statement in C img1

As per the observation, we can see how the program works:

  • We declared a variable i.
  • We made for a loop by initializing the value of I to 0 and incrementing it by one till the number is less than 20.
  • And then we have another condition that if, modulo division of I with 2 is zero; that is it would denote an even number, then we are using our continue statement, which is, in turn, iterating the program back to them for a loop by incrementing its value by 1.
  • If the variable i will not be an even number, then the print statement is being executed, which in turn prints only odd numbers.

Now, what if we try to write some code or some statements after a continue statement? Will those are executed? Let’s check here.

For the above program, we have just modified we have just added a print statement below continue statement.

Code:

#include <stdio.h>
int main()
{
int i;
for(i=0;i<20;i++)
{
if(i%2==0)
{
continue;
printf("This will not be executed");
}
printf("%d ",i);
}
}</code>

Output:

Continue Statement in C img2

The same output as the first example program is obtained. Through this change, we can tell that after the continue statement is encountered; the iteration directly goes above again. Any statement to the immediate below or continue statement present in the same loop or if/else condition will not be executed.

Example #2

Let a movie theater has 30 seats and 5 seats from 15th seat are booked, so how can we show the remaining seats to people.

We are trying to write this using a do-while loop and we can write in a similar way as above just to display the numbers.

Code:

#include <stdio.h>
int main () {
int a = 0;
/* do loop execution */
do {
if( a == 15) {
a = a + 5;
continue;
}
printf("%d ", a);
a++;
} while( a < 30 );
return 0;
}

Output:

Continue Statement img3

These are the steps on how we are writing this code.

  • We initialized the value of a to zero and the having do loop.
  • Then we are having if a loop with the condition of variable a being equal to 15.
  • Then incrementing the value of a by 5 and then using continue to start the loop again.
  • Then we can get the numbers after 20 and then our while loop will check the value for ‘a’ value till 30 numbers.

Example #3

Print stars in increasing order and skips printing the row with star count 7.

Code:

#include <stdio.h>
int main()
{
int a = 1;
int count = 0;
for (int a = 1; a <= 10; )
{
if (count < a)
{
printf("* ");
count++;
continue;
}
if(count==6)
{
count++;a++;
continue;
}
if (count == a)
{
printf("\n");
a++;
count = 0;
}
}
}

Output:

continue img4

What exactly did we do here?

  • Firstly, we declared and initialized two values. One for the line count denoted by ‘a’ and other for the number of star count that is denoted by ‘count’.
  • Then we are running for loop for the number of lines less than 10.
  • And inside that, we have 3 if loops.
  • The first if loop would print the stars and makes sure that the line number is in sync with the number of the stars.
  • The third if the loop would increment the line number once the line count and a number of stars count are equal.
  • The second if the loop is our condition where if we encounter count as 6, we are just incrementing both count and line number such that line number 7 having 7 stars is prohibited from printing.

We have seen different examples here.

So as an exercise can you try printing only even the number of stars in decreasing order starting from number 20?

And in the same way, can you try writing this continue statement in a case functionality?

Conclusion – Continue Statement in C

I hope you had a good time learning about continue statement and understood where exactly we need this statement. We had discussed where we can use and how it can help us in different programming scenarios. Keep trying and playing around continue statements in different scenarios and have fun learning.

Recommended Articles

This is a guide to Continue Statement in C. Here we discuss the syntax, flowchart along with the different examples of continue statements in c with code implementation. You may also look at the following articles to learn more –

  1. Switch Statement in C
  2. C Storage Classes
  3. Swapping in C
  4. Best C Compilers

C Programming Training (3 Courses, 5 Project)

3 Online Courses

5 Hands-on Projects

34+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
C Programming Tutorial
  • Control Statement
    • Control Statements in C
    • If Statement in C
    • If-else Statement in C
    • Else if Statement in C
    • Nested if Statement in C
    • #else in C
    • Structure Padding in C
    • Nested Structure in C
    • Continue Statement in C
    • Break Statement in C
    • Switch Statement in C
    • Goto Statement in C
  • Basic
    • Introduction to C
    • What is C
    • Career in C Programming
    • Advantages of C
    • How to Install C
    • Best C Compilers
    • Data Types in C
    • Variables in C
    • C Keywords
    • C Command
    • Command Line Arguments in C
    • C Literals
    • Constants in C
    • Unsigned Int in C
    • String in C
  • Pointers
    • Pointers in C
    • Null pointer in C
    • Function Pointer in C
    • Double Pointer in C
    • Void Pointer in C
    • Const Pointer in C
    • Dangling Pointers in C
    • Pointer Arithmetic in C
  • Operators
    • C Operators
    • Arithmetic Operators in C
    • Relational Operators in C
    • Assignment Operators in C
    • Logical Operators in C
    • Conditional Operator in C
    • Modulus Operator in C
    • Ternary Operator in C
    • Address Operator in C
    • Unary Operator in C
    • Operators Precedence in C
    • Left Shift Operator in C
  • Loops
    • Loops in C
    • For Loop in C
    • While Loop in C
    • Do While Loop in C
    • Nested Loop in C
    • Infinite Loop in C 
  • Function
    • Math Functions in C
    • Hashing Function in C
    • Recursive Function in C
    • Power Function in C
    • fputs in C
    • C puts() Function
    • fprintf() in C
    • fseek() in C
    • Stderr in C
    • ASCII Value in C
    • strcat() in C
    • Inline Function in C
    • sizeof() in C
    • Function Prototype in C
    • C ftell()
  • Array
    • Arrays in C Programming
    • 2-D Arrays in C
    • 3D Arrays in C
    • Multidimensional Array in C
    • Array Functions in C
    • Strings Array in C
  • Sorting
    • Sorting in C
    • Heap Sort in C
  • Advanced
    • Constructor in C
    • Encapsulation in C
    • C Storage Classes
    • Static Keyword in C
    • File Handling in C
    • Queue in C
    • Hexadecimal in C 
    • typedef in C
    • Memory Allocation in C
    • Linked List in C
    • Volatile in C
    • Tokens in C
    • Expression in C
    • Regular Expression in C
    • Error Handling in C
    • Types of Errors in C
    • Preprocessor in C
    • Preprocessor Directives in C
    • fscanf() in C
    • #Pragma in C
    • #ifndef in C
    • #undef in C
    • Macros in C
  • C programs
    • Patterns in C Programming
    • Star Patterns in C
    • Number Patterns in C
    • Swapping in C
    • Reverse Number in C
    • Palindrome in C Program
    • Factorial in C
    • Fibonacci Series in C
    • Square Root in C
    • Random Number Generator in C
    • Prime Numbers in C
    • Escape Sequence in C
    • Reverse String in C
    • Leap Year Program in C
    • Anagram Program in C
    • Strong Number in C
    • String Concatenation in C
    • C Programming Matrix Multiplication
    • Decimal to Octal in C
    • Expression Evaluation in C
    • Decimal to Hexadecimal in C
  • Interview question
    • C Programming Interview Questions

Related Courses

C Programming Training Course

C++ Training Course

Java Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C Programming Training (3 Courses, 5 Project) Learn More