Break statement in switch statement

What does a break statement do in the switch statement?

E

Expert

Verified

Switch statement is the selection control statement that is used to handle multiple choices and transfer control to the case statements within its body. The following code snippet shows an example of the use of the switch statement in C#:

switch(choice)
{
 case 1:
 console.WriteLine("First");
 break;
 case 2:
 console.WriteLine("Second");
 break;
 default:
 console.WriteLine("Wrong choice");
 break;
}

In switch statements, the break statement is used at the end of a case statement. The break statement is mandatory in C# and it avoids the fall through of one case statement to another.

   Related Questions in DOT NET Programming

©TutorsGlobe All rights reserved 2022-2023.