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;
 
namespace break_statement
{
  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#.


     

Previous Page Next Page