C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

What does a break statement do in the switch statement?

0 votes
19 views
asked by john Guru (27,140 points)

1 Answer

0 votes

 

 
The switch statement is a 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.
 
answered by keem Expert (13,240 points)

Related questions

0 votes
1 answer 37 views
37 views asked by john Guru (27,140 points)
0 votes
1 answer 60 views
0 votes
1 answer 1,142 views
+1 vote
1 answer 50 views
0 votes
1 answer 1,393 views
...