Solved Examples · Example 34
Q.Write a C program to illustrate the use of the continue statement in a for loop.
The textbook presents this worked program, transcribed exactly as printed (including its printed errors):
#include <stdio.h>
void main()
{
int kount, sum1=0, sum2=0, limit, rem;
printf("Enter the limi\n");
scanf("%d", &limit);
for (kount=0, kount<limit; kount++)
{
rem=(kount%2);
if (rem==0)
sum1+=kount;
continue; /*bypassing next part */
sum2+=kount;
} /*End of for */
printf("The sum even numbers=%d\n", sum1);
printf("The sum odd numbers=%d\n", sum2);
} /* End of main()*/
Sample output printed in the textbook:
Enter the limit
10
The sum of even numbers = 20
The sum of odd numbers = 25
#include <stdio.h>
void main()
{
int kount, sum1=0, sum2=0, limit, rem;
printf("Enter the limi\n");
scanf("%d", &limit);
for (kount=0, kount<limit; kount++)
{
rem=(kount%2);
if (rem==0)
sum1+=kount;
continue; /*bypassing next part */
sum2+=kount;
} /*End of for */
printf("The sum even numbers=%d\n", sum1);
printf("The sum odd numbers=%d\n", sum2);
} /* End of main()*/
Enter the limit
10
The sum of even numbers = 20
The sum of odd numbers = 25
Karnataka PUCTextbookLongImportance★★★★★est
95% · 147/154 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →[!TLDR]
continue skips the remainder of a pass for even values, so evens go to sum1 (20) and odds to sum2 (25) for limit 10.
The continue statement abandons the current iteration and jumps straight to the loop's update step, without leaving the loop (unlike break). Placed inside the if for even numbers, it adds the value to the even total and then skips over the odd-total line, so only odd numbers reach sum2. This cleanly separates the two accumulations within a single loop. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.