C# Break Statement

In this chapter you will learn:
  • What is break statement in C#?
  • What is the functionality of break statement?
  • How to use break statement in programming?

The break statement is used to terminating the current flow of the program and transfer controls to the next execution.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace break_statements
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;

            while (i < 100)
            {
                Console.WriteLine(i);
                if (i == 20)
                {
                    Console.WriteLine("breaking the current segment...");
                    break;
                }
                i++;
            }
            Console.ReadLine();
        }
    }
}

 

Output

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
breaking the current segment.... __

Summary

In this chapter you learned what the break statement is in C# and how to use it in program. In next chapter you will learn about continue statement in C#.

More Articles

 

Share your thought



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.