Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I still need to use break after I use return in switch/case?

switch (input) {
  case 1: 
    return "this is one";
    break;
    
  default:
    break;
}

can return break the code? Or it does what break does after return the result?

like image 812
Donghui Ma Avatar asked Nov 19 '17 07:11

Donghui Ma


1 Answers

return terminates your function, so the code won't continue executing (and potentially falling through to the next case block). There's no point in using break in such a situation.

like image 138
Mureinik Avatar answered Sep 27 '22 21:09

Mureinik