c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

How to use foreach with the continue?

| | CSharp

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