C Programming Tutorial

C Programming Tutorial

Continue Statement in C

Hello Everyone, In this article, we will cover the concept of Continue Statement in C Programming. In this topic we will cover what is continue statement, its syntax, how it works, and practical examples of its use. Whether you’re new to C or have some experience, this guide will help you to understand Continue Statement in C effectively. Let’s get started.

In C programming, the “continue statement” is used to skip over a portion of a loop and continue with the next iteration of the loop. When the “continue” statement is encountered within a loop, the current iteration of the loop is terminated, and the program immediately jumps to the beginning of the next iteration of the loop.

The “continue” statement is often used in loops where certain conditions need to be skipped over. For example, if you have a loop that processes a list of items and you want to skip over any items that meet a certain condition, you can use the “continue” statement to skip over those items and continue processing the rest of the items in the list.

Example of how the “continue” statement can be used in a loop

for (int i = 0; i < 10; i++) {
    if (i % 2 == 0) {
        continue; // skip over even numbers
    }
    printf("%d\\n", i);
}

In this example, the loop processes the numbers 0 to 9, but the “continue” statement is used to skip over any even numbers. As a result, only the odd numbers (1, 3, 5, 7, and 9) are printed to the console.

C Program to explain continue statement

#include <stdio.h>
int main() {
    int i;

    for (i = 1; i <= 10; i++) {
        if (i % 2 == 0) {
            continue;
        }
        printf("%d\\n", i);
    }

    return 0;
}

In this program, we use a for loop to iterate over the values from 1 to 10. However, when the loop variable i is even, the continue statement is executed, causing the program to skip over the printf() statement and move on to the next iteration of the loop.

As a result, when we run the program, it only prints the odd values (1, 3, 5, 7, and 9) and skips over the even values (2, 4, 6, 8, and 10).

Here’s the output of running the program:

1
3
5
7
9
Share This Article