+ 2

Why can't we write default case at the begining in the switch loop? Is it compulsory to write it at end only?

I would like to write default at begining with break statement. is that fine?

16th Oct 2017, 4:13 PM
Manikanta
Manikanta - avatar
3 Answers
+ 11
Granted that you placed a break after the default case, it will work the same way no matter where it is placed within a switch statement.
16th Oct 2017, 4:21 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
It will works the same if you put default statement even in the beginning, position does not matters inside a switch statement.
16th Oct 2017, 5:14 PM
Lakshay
Lakshay - avatar