Does this smell message make bad?

Switch(some case) {
    case 1:
           // compute something ...
           return something;
           break;
    case 2:
           // compute something ...
           return something;
           break;

/* some more cases ... */

    case X:
           // compute something ...
           return something;
           break;
    default:
           // do something
           return something;
           break;
}

To my mind:

Assuming this switch statement is justified, the return and break just don't look right or aren't true.

The gap is clearly redundant, but the omission of a bad style (or is this bad style to start with?)?


I personally do not do this, but there are some of them in code-based work. And no, I'm not going to be self-confident and correct the code base.

+5
source share
10 answers

The C # compiler gives a warning if you say that a break is unreachable code. So in my book this is a bad form to both come back and break.

+11
source

, - . . .

, , , - , , , , .

:

, switch, . ? Java, ? ( #, .)

, , , - , .

+21

-, "break". , , " ! !".

+5

:

switch(some case) {
    case 1:
           // compute something ...
           break;
    case 2:
           // compute something ...
           break;
/* some more cases ... */
    case X:
           // compute something ...
           break;
    default:
           // do something
           break;
}
return something;
+5

, , ...

" 1" , , , , .

- , , "somethings" , switch..

return somethings [index]

+1

. . , , .

0

.

. . , Try-Catch (oop goto).

, , .

0

- case.

, . , , , , .

Personnaly , , , , . , - - , , , ... , , , ( , ).

0

switch .

, l99057j, , , , , / / , switch. - , , .

0

. , : , , {} , : , . 100 , .

0

All Articles