Break in C#


Break will exit from the loop.

Break will exit from the loop without waiting until given condition for the loop is false.

Within the looping control statements you can use the statements break and continue.

Example program for Break in C#


using System;

 

//Program to print numbers 1 to 10

namespace ProgramCall

{

    class BreakExample

    {

        static void Main()

        {

            int num = 0;

 

            while (true)

            {

                //Increment the number

                num++;

                Console.WriteLine(num);

 

                //if num is 10 , break the loop

                if (num == 10)

                    break;

            }

 

            Console.ReadLine();

        }

    }

}


Output
1
2
3
4
5
6
7
8
9
10



break in c#.net, c# break continue, c# break while, c# break for loop, c# break foreach, c# break statement, c# continue break ,break continue c#, c#.net break continue