Skip to content

C# Feature - break vs continue

break exits the nearest loop or switch immediately. continue skips the rest of the current loop iteration and moves to the next one.

C# 1.0 (2002)

for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] < 0)
{
// choose the right control statement here
}
}
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] == 0) continue;
if (numbers[i] < 0) break;
Console.WriteLine(numbers[i]);
}
  • Use break when further iteration has no value.
  • Use continue when only one iteration should be skipped.