The continue statement helps skip the rest of the current loop cycle and move to the next one. It lets you ignore some steps when a condition is met.
0
0
Continue statement behavior in C Sharp (C#)
Introduction
When you want to skip processing certain items in a list but continue checking the rest.
When filtering data inside a loop and ignoring unwanted cases.
When you want to avoid nested if-else by skipping early in a loop.
When you want to improve readability by handling special cases quickly inside loops.
Syntax
C Sharp (C#)
continue;The continue statement can only be used inside loops like for, while, or foreach.
When continue runs, it skips the rest of the current loop cycle and moves to the next iteration.
Examples
This loop skips printing the number 2 by using
continue.C Sharp (C#)
for (int i = 0; i < 5; i++) { if (i == 2) continue; Console.WriteLine(i); }
This loop skips printing the letter 'l' in the word "hello".
C Sharp (C#)
foreach (var ch in "hello") { if (ch == 'l') continue; Console.Write(ch); }
Sample Program
This program prints numbers from 1 to 5 but skips number 3 using the continue statement.
C Sharp (C#)
using System; class Program { static void Main() { for (int i = 1; i <= 5; i++) { if (i == 3) { continue; // Skip number 3 } Console.WriteLine($"Number: {i}"); } } }
OutputSuccess
Important Notes
Using continue can make your loops easier to read by handling special cases early.
Be careful not to create infinite loops by skipping the part that changes the loop variable.
Summary
continue skips the rest of the current loop cycle and moves to the next.
It works only inside loops like for, while, and foreach.
Use it to ignore certain cases without stopping the whole loop.