Skip to content

break vs continue

break exits the nearest loop or switch. continue skips to the next iteration of the nearest loop.

KeywordWhat it doesTypical use
breakExit loop/switch immediatelyFound target, error condition
continueSkip rest of current iterationFilter items, skip invalids
for (var i=0; i<10; i++)
{
if (i == 7) break; // stop entirely
if (i % 2 == 0) continue; // skip evens
Console.WriteLine(i);
}

+---------+ +-----------+ +---------+ | start i | ---> | condition | ---> | body | +---------+ +-----------+ +---------+ / \ continue break (next iter) (exit loop)