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)
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.