Closed adamzzq closed 7 months ago
I think using return itself is sufficient for this case as it immediately exits foo. Any other lines after return will be unreachable, including break.
Yes, I agree with @JackieNeoCEG. Just to add on, using break
statements in place of return
statements would be necessary if you have additional code after the switch
statement and need to run it. But in this case, it is not necessary (and unreachable due to aforementioned reason by @JackieNeoCEG ).
Thanks, my friends
Hi prof, may I ask for a method that involves a switch like this, is there a need to add a
break;
at the end of each case? Because when I add abreak
after areturn
, the IDE warns me that the break line is an unreachable statement.