Question

C program to skipping Even Numbers in a for Loop using continue statement

Updated on May 31, 2025 | By Learnzy Admin | 👁️ Views: 203 students

Solution
✔ Verified

In C programming, you can use the continue statement to skip certain iterations in a loop. If you want to skip even numbers in a for loop, the continue statement can be used inside the loop to bypass the rest of the loop’s body whenever an even number is encountered.

How it Works:

  • The for loop runs from 1 to 10.
  • Inside the loop, there's an if statement that checks whether the current number i is even using the condition i % 2 == 0. The modulus operator (%) returns the remainder when i is divided by 2, and if the remainder is 0, the number is even.
  • If the number is even, the continue statement is executed. This causes the loop to skip the remaining part of the body and go directly to the next iteration, thus not printing the even numbers.
  • The odd numbers (when i % 2 != 0) are printed as they do not trigger the continue statement.
#include <stdio.h>

int main() {
    // Loop from 1 to 10
    for (int i = 1; i <= 10; i++) {
        // Check if the number is even
        if (i % 2 == 0) {
            continue;  // Skip the rest of the loop for even numbers
        }
        // Print odd numbers
        printf("%d\n", i);
    }
    
    return 0;
}

Output

1
3
5
7
9
Was this solution helpful? 23
Click here to download practice questions on Continue statement in C

More Questions on Continue statement in C