What does "control falls through a switch statement" mean in this context? Control just moves on to the next statement?
I thought if there is no match and a default case doesn't exist it will raise an exception. Is it not true?
What does "control falls through a switch statement" mean in this context? Control just moves on to the next statement?
I thought if there is no match and a default case doesn't exist it will raise an exception. Is it not true?
10 Comments
manitcor@lemmy.intai.tech · 4 pts · 3y
Means it will be skipped entirely
jim_stark@programming.dev · 3 pts · 3y
I see, thank you! I got confused with "control falls through a switch statement" and "C++ style fall through in switch statements".
manitcor@lemmy.intai.tech · 1 pts · 3y
C# will let you forget simple things and crash or compile error further down the line.
lmaydev@vlemmy.net · 2 pts · 3y
Unlike c++? Hehe
davidwengier@aussie.zone · 2 pts · 3y
A switch statement will let control fall through. A switch expression will no, and will throw an exception (and there will also be a compiler warning that it's not exhaustive before you even run the code)
jim_stark@programming.dev · 3 pts · 3y
I think even
switchstatement doesn't allow it because every case needs to be terminated with eitherbreak,returnorraise. One needs to usecase gotoif one wants fall thought like behavior:RonSijm@programming.dev · 3 pts · 3y
A
switchstatement allows fall through when the case itself doesn't have an implementation.For example this is also considered a fall through:
jim_stark@programming.dev · 1 pts · 3y
TIL!!!
Thank you!