Control cannot fall through from one case label to another?
-
i'd like to get my code executed from case 1 to case 3, but i got this error . Here are my codes : int State = 1 switch (State) { case 1: a=1; a++; State++; case 2: State++; case 3: a=0; } Thanks
No, you can't fall through from one case/default into another one. You can only break or change the program flow somehow, e.g. return, throw, and goto. IMO goto and label can be acceptable inside a switch. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
i'd like to get my code executed from case 1 to case 3, but i got this error . Here are my codes : int State = 1 switch (State) { case 1: a=1; a++; State++; case 2: State++; case 3: a=0; } Thanks