Continue Statement

C#C# continue statement is used to skip some piece of code inside the loop.  In some cases, you don’t want to execute some piece of code during your looping process, then this statement comes in handy.  The C# sample code is given below to demonstrate the use of continue statement where we are skipping 1 name from printing on the screen.

using System;

namespace MyHelloWorld
{   
    class Program
    {
        static void Main(string[] args)
        {
            string[] names = { "Robert", "Albert", "Mark" };

            foreach (string name in names)
            {                

                if (name == "Albert")
                {
                    continue;
                }

                Console.WriteLine(name);
            }

        }
    }
}

 

Output:

Robert
Mark
Press any key to continue . . .

 

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •