So I'm guessing that the default statement doesn't require a break because it's already at the end of the switch statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

So I'm guessing that the default statement doesn't require a break because it's already at the end of the switch statement?

23rd Mar 2016, 9:40 PM
Sara M
Sara M - avatar
4 Answers
+ 1
break is use to stop compiler and leave the statements after that and leave the scope and default is always at ending so there is no statement after default so no break is required
13th Jun 2016, 5:06 PM
DJ Shiva & DJ Baba Shiv-Shekhar
DJ Shiva & DJ Baba Shiv-Shekhar - avatar
0
Shortly - yes. Any case that is the last one doesn't require break but it's a bad practice. Also it is not true that default has to be last.
2nd Apr 2016, 8:28 AM
Przeszczep
0
default case is run when no other case is true so it is a extra option which is neccesary
13th Jun 2016, 8:59 AM
Iman Ali
Iman Ali - avatar
0
break is required if you only want one task with one case,eg. switch(ch){ case 1: case 2:{ //some task break;} case 3://task 3 case 4: return; default:cout<<"wassup"; } cout<<"\n nothing"; if ch is 3,task 3 will be executed and then the program will return, hence output would be whatever task 3 was. had there been a break after task 3, output would be //task 3's output nothing hope you understood it :)
18th Jun 2016, 6:35 AM
Tushar Purang