How do I use the continue statement?

Category: Introduction, viewed: 2K time(s).

The continue statement will passes the control to the next iteration. In the example below we tell the enclosing for loop statement to skip or continue to the next iteration if the i variable is an even number.

using System;

namespace Kodecsharp.Example.Intro
{
    class ContinueDemo
    {
        [STAThread]
        public static void Main(string[] args)
        {
            for (int i = 0; i <= 10; i++)
            {
                if (i % 2 == 0)
                {
                    continue;
                }
                Console.WriteLine(i);
            }
            Console.ReadLine();
        }
    }
}

The result of our program is here:

1
3
5
7
9
Powered by Disqus