Continue Statement in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

The continue statement in C is used within loops to skip the current iteration and proceed to the next one. It helps control the flow of the program and is often used to skip specific iterations based on a condition.

What is continue in C?

The continue statement in the C programming language is a control statement used primarily within loops (such as "for" and while loops) to alter the flow of program execution. When encountered, continue immediately jumps to the next iteration of the loop, bypassing any code that follows it within the current iteration. This is particularly useful when you want to skip specific parts of a loop based on a certain condition. For example, you might use continue to avoid executing a block of code for certain loop iterations. By doing so, it enables more efficient and fine-grained control over loop execution, making it a valuable tool for managing program logic and iteration in C.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of continue in C

In C, continue is reserved as a keyword, and the syntax of the continue statement is as follows -

Use of continue in C

  • Skip Current Iteration: The continue statement is used to skip the remaining code within the current iteration of a loop.
  • Control Loop Flow: It allows for fine-grained control of loop execution by bypassing specific iterations.
  • Conditional Skipping: You can use continue in combination with conditional statements to skip iterations based on certain conditions.
  • Efficiency: It helps improve the efficiency of your code by avoiding the execution of unnecessary code during specific loop iterations.
  • Common Use Cases: It is often employed to handle exceptional cases or to exclude specific values from loop processing.
  • Versatility: continue is compatible with different loop types, such as "for," "while," and "do-while" loops.
  • Programming Logic: It is a valuable tool for managing program logic and ensuring that the code executes as intended within loops.
  • Careful Usage: Care should be taken when using continue to avoid potential infinite loops or unintended logic errors.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Examples of Continue Statement in C

Let us look at a simple example to understand how the continue statement is used in C.

Output

Here, the above code prints the variable number when the value of number is greater than five and skips the iteration using the continue statement when the value of number is less than five.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

How Continue Statement Works?

  • Encounter "continue": When a continue statement is encountered in a loop, it immediately skips the remaining code within the current iteration and moves to the next one.
  • Skips Code: All code following continue in the current iteration is ignored.
  • Conditional Use: It is often used with conditional statements to skip specific iterations based on conditions, allowing fine-grained loop control.

Flowchart of continue in C

Now that we understand, the continue statement is used to skip iterations in a loop. Let us see a flow diagram to visualize how continue works in a loop.

CONTINUE STATEMENT IN C

From the flow chart mentioned above, you can observe that as soon a continue statement is encountered inside a condition, the execution of code skips the conditions following the continue statement, and the next iteration of the loop begins till the loop condition is met. The loop condition continues till the condition of the loop is satisfied, and the program exists loop when the condition becomes false.

Notice the code below the continue statement only executes when the continue statement is not encountered inside the loop body.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Difference between break and continue Statements in C

Aspectbreak Statementcontinue Statement
UsageUsed to exit the loop prematurely and proceed with the code outside the loop.Used to skip the remaining code within the current iteration and continue with the next iteration of the loop.
EffectTerminates the entire loop when encountered.Skips the code following the continue statement in the current iteration, but the loop continues with the next iteration.
ControlProvides an abrupt exit from the loop structure.Provides a means to control loop execution with fine-grained skipping.
Common Use CasesTypically used to exit a loop early based on certain conditions.Commonly used to exclude specific iterations of a loop based on specific conditions.
ScopeAffects the entire loop structure.Affects only the current iteration of the loop.

Learn more about Difference between break and continue Statements in C.

Conclusion

  • Continue statement in C passes programs control to the next iteration of the loop, i.e., nearest enclosing do-while, while, or for statement skipping any remaining statement in the loop body.
  • The syntax of the continue statement in C is - continue;.
  • Continue statement in C can be used with for, while, and do-while loop.
  • Continue statement in a for loop causes evaluation of loop condition of the for loop statement. The code re-evaluates the conditional expression, and depending on the result, the loop either terminates or continues iteration to the loop body.
  • For both the while and do-while loops, the continue statement skips the iterations and re-evaluates the loop's conditional expression.

See Also