How do I use the continue statement?

Category: Introduction, viewed: 127 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
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Network Sites

Statistics

Locations of visitors to this page