Is default case compulsary? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is default case compulsary?

7th Jan 2019, 2:48 PM
Shravani
Shravani - avatar
2 Answers
+ 4
No, you can use switch without default. Just that the cases not listed in case won't be handled.
7th Jan 2019, 2:58 PM
Gordon
Gordon - avatar
+ 3
No. Let's say you have a number between 1 and 10. If you only define case 1, 2 and 3, in case of 4 to 10 nothing happens.
7th Jan 2019, 3:00 PM
HonFu
HonFu - avatar