07 Aug, 2007 · 1 minute read
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 (int I = 0; I < 10; I++)
{
if (I % 2 == 0)
{
continue;
}
Console.WriteLine(I);
}
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);
}
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 != "");