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
18 views
asked Feb 24, 2014 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 Feb 24, 2014 by keem Expert (13,240 points)

Related questions

0 votes
1 answer 36 views
36 views asked Feb 18, 2014 by john Guru (27,140 points)
0 votes
1 answer 59 views
59 views asked Feb 24, 2014 by john Guru (27,140 points)
0 votes
1 answer 1,119 views
+1 vote
1 answer 49 views
0 votes
1 answer 1,392 views
1,392 views asked Dec 18, 2013 by john Guru (27,140 points)
...