0

Why do we use default statement in switch cases?

30th Jun 2017, 7:13 PM
Shauzab Khan
Shauzab Khan - avatar
5 Answers
+ 1
ohh okay okay. I get it. it's for the situation where all the given condition goes false, isn't it?
30th Jun 2017, 7:17 PM
Shauzab Khan
Shauzab Khan - avatar
+ 1
in case if none of cases were match
30th Jun 2017, 8:15 PM
Hetbo.net
Hetbo.net - avatar
+ 1
Well, just for fun let us assume that the default statement ain't there and you have only the case statements. What if they all turn out false!! What is the compiler to do now..... Thus you have an error or a bug in your program. It is to avoid this you use a default statement.
5th Jul 2017, 3:08 PM
Pramod Nagaraj
Pramod Nagaraj - avatar
0
if none of the case is satisfied then the default case is displayed
30th Jun 2017, 7:16 PM
‎ ‏‏‎Anonymous Guy
0
That's true.
30th Jun 2017, 9:07 PM
Jonas Schröter
Jonas Schröter - avatar