Use of Break statement in switch statement

Explain the function of break statement in a switch statement with example?

E

Expert

Verified

Switch statement is the selection control statement which is used to handle several choices and move control to a case statements within its body. 

Following code shows the example of the use of a switch statement in C#: 

switch(choice)

{

 case 1:

 console.WriteLine("First"); 

 break;

 case 2:

 console.WriteLine("Second");

 break;

 default:

 console.WriteLine("Wrong choice");

 break;

}

The break statement is used at the end of the case statement. Break statement is compulsory in C# and it avoids the fall through of one case statement to other.

   Related Questions in DOT NET Programming

©TutorsGlobe All rights reserved 2022-2023.