C programming - continue statement

In C programming, the continue statement is used to immediately skip to the next iteration of a loop, without executing any remaining statements in the current iteration.

The continue statement is typically used within loops such as for, while, and do-while. When the continue statement is executed within a loop, it causes the loop to immediately skip to the next iteration, without executing any remaining statements in the current iteration.

Here's the basic syntax of the continue statement:

for (int i = 0; i < n; i++)
{
    // statements to be executed
    if (some_condition)
    {
        continue;
    }
    // more statements to be executed
}
Sou‮:ecr‬www.theitroad.com

In this example, if some_condition evaluates to true, the continue statement will be executed and the loop will skip to the next iteration without executing any remaining statements in the current iteration.

Here's another example of using the continue statement within a while loop:

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

In this example, the program will print all odd numbers from 1 to n. When the value of i is even, the continue statement is executed and the loop immediately skips to the next iteration without executing the printf statement.