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.