Essential C# Looping  Suggest an edit

continue

In addition to break, there is also the keyword continue. Instead of breaking completely the loop, it will simply skip the current iteration. It could be useful if you don’t want some code to be executed if a particular value is set.

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 well-defined exit conditions, may not benefit as much.


Table Of Contents
22 Enum
25 GUID
28 Looping
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close