when is it necessary to use the switch command and the default command | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

when is it necessary to use the switch command and the default command

12th Apr 2017, 2:35 PM
TheCoder4000
TheCoder4000 - avatar
2 Answers
+ 5
The switch statement is generally used for a variable with discrete values. The default block runs if there is no case which matches.
12th Apr 2017, 2:40 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
- 1
It's handy if you want to check a variable to be many different values. In that case it's shorter than an if-if else-else thing.
12th Apr 2017, 2:40 PM
merkrafter