completecsharptutorial.com

CompleteCsharpTutorial.Com




C# Break Statement

Objective

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 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#.



Like Us

Basic C#