continue

suggest change

In addition to break, there is the keyword continue. Instead of leaving the loop, it skips the rest of the current iteration. That is useful when some of the loop body should not run for a particular value.

Here’s a simple example:

for (int i = 1; i <= 10; i++)
{
    if (i < 9)
        continue;

    Console.WriteLine(i);
}

Will result in:

9
10

Note: continue is often most useful in while or do-while loops. for loops with a well-defined exit condition may not benefit as much.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents