Friday, 17 August 2018

C#: continue statement

‘continue’ statement skips the current iteration of for, while, do-while, for-each loops.

Syntax
continue;

Program.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i < 10; i++)
        {
            if (i % 2 == 0) continue;
            Console.WriteLine(i);
        }
        Console.WriteLine("I am out of the loop");
    }
}

Output
1
3
5
7
9
I am out of the loop



Previous                                                 Next                                                 Home

No comments:

Post a Comment