A break
statement only breaks the closest switch/loop that it is called in.
In your example, the break
statements of the inner switch
would only break out of the inner switch
, execution would return to case 0
of the other switch
. And then, since that case 0
does not have a break
of its own, execution would fall through to case 1
, which also does not have a break
, so execution would fall through to case 4
, which does have a break
to end the outer switch
.
This is certainly true in C and C++, anyway. Not necessarily in other languages. For example, Delphi does not fall-through between case blocks. Break
can be used to end a case
block early, but it is optional, the block is finished when the end of its scope is reached.
solved C++ Multi Switch and Break?