- 2072 Kartik · 1+2 marks
Purpose of continue statement
Short answer
The continue statement skips the remaining statements of the current loop iteration and immediately proceeds to the next iteration. It can only be used inside loops: for, while, and do-while.
What are the purpose of the continue statement? Within which control statements can continue statement be included?
Purpose of continue
The continue statement skips the remaining statements of the current iteration of a loop and moves control directly to the next iteration (in a for loop, to the update expression; in while and do-while, to the condition test). It lets us ignore particular cases without leaving the loop.
#include <stdio.h>
int main(void)
{
int i, sum = 0;
for (i = 1; i <= 10; i++)
{
if (i % 2 == 0)
continue; /* skip even numbers */
sum += i;
}
printf("Sum of odd numbers 1..10 = %d\n", sum);
return 0;
}
Output:
Sum of odd numbers 1..10 = 25
Where it can be used
continue can be used only inside loops: for, while and do...while. It may be written inside an if or a switch that is itself inside a loop, but not outside a loop.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Need of control statements · Computer Programming, chapter 5 · asked 2×
- Break versus continue · Computer Programming, chapter 5 · asked 3×
- Purpose of semicolon · Computer Programming, chapter 3
- Purpose of PID tuning; computer control benefits · Embedded System, chapter 7
- Second law statements; Kelvin-Planck and Clausius equivalence · Fundamental of Thermodynamics & Heat Transfer, chapter 5
- Assembler statements and directives · Microprocessor, chapter 3 · asked 4×
- Problem statement and UML building blocks · Object Oriented Analysis and Design, chapter 2