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

Partho Sarathi

07 Aug, 2007 · 1 minute read

  • Share:

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 != "");
  • Share:

The cleanest blogging platform


2024 © Maxotek. All rights reserved.