This articles describes how to use foreach with the continue. If continue statement is used within the loop body, it immediately goes to the next iteration skipping the remaining code of the current iteration.
static void Main(string[] args)
{
try
{
var names = new List<string>() { "Car", "Bike", "Bus" };
foreach (string name in names)
{
if (name == "Bike")
{
continue;
}
Console.WriteLine(name);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
Output:
Car
Bus