Published · 1 min read

What statements can come with “continue” statement in C#

The continue statement is used to pass the control to the next iteration of the loop it is in. So, it can only be used with loops.

The continue statement is used to pass the control to the next iteration of the loop it is in. So, it can only be used with loops.

for

for (int I = 0; I < 10; I++)
{
    if (I % 2 == 0)
    {
        continue;
    }
    Console.WriteLine(I);
}

foreach

int[] Numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
foreach (int Number in Numbers)
{
    if (Number % 2 == 0)
    {
        continue;
    }
    Console.WriteLine(Number);
}

while/do while

string Name = "";
do
{
    Console.Write("Enter a Name:");
    Name = Console.ReadLine();
    if (Name == "Parastratiosphecomyia stratiosphecomyioides")
    {
        // The animal with the longest Scientific Name???
        continue;
    }
    if(Name != "")
        Console.WriteLine("{0} is a good name", Name);

} while (Name != "");
Partho Sarathi

Partho Sarathi

Founder, Maxotek

C# & .NET

Our blog

Related posts

Tutorials, notes and news from Maxotek.

View all posts

See what Maxotek makes

Monitoring, conversion tools and more, built by the same people who wrote these posts.