continue statement

continue statement restarts the loop iteration.

The following code only prints out 6,7,8,9,10.

 
using System;

class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i <= 10; i++)
        {
            if (i <= 5)
            {
                continue;
            }
            Console.WriteLine(i);

        }

    }
}

The output:


6
7
8
9
10

The following code combines the modular operator and continue statement to print out odd numbers only.

 
using System;

class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i < 20; i++)
        {
            if (i % 2 == 0)
            {
                continue;
            }
            Console.WriteLine(i);
        }


    }
}

The output:


1
3
5
7
9
11
13
15
17
19
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.