Friday, 17 August 2018

C#: break statement

‘break’ statement is used to come out of the loop.

Syntax
break;

Program.cs
using System;

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

Output
0
1
2
3
4
I am out of the loop



Previous                                                 Next                                                 Home

No comments:

Post a Comment