C# Feature - break vs continue
Overview
Section titled “Overview”break exits the nearest loop or switch immediately. continue skips the rest of the current loop iteration and moves to the next one.
Introduced In
Section titled “Introduced In”C# 1.0 (2002)
Before
Section titled “Before”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]);}Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Use
breakwhen further iteration has no value. - Use
continuewhen only one iteration should be skipped.