The reason this works is somewhat non-intuitive: case
labels of a switch
statement act very much like regular labels, i.e. the ones designed for use with goto
statement. You can place such labels anywhere in your code.
It turns out that the same rule applies to the case
label: you can place them anywhere inside their corresponding switch
statement, which incidentally includes the bodies of any nested loops.
The reasons why you may want to place labels inside control statements within the body of your switch
statement are even less intuitive: it turns out that you can perform loop unrolling with a cumbersome-looking but very intuitive construct called Duff's Device. It is this construct that lead to popularizing the idea of embedding case labels inside other control structures within switch
statements.