[Solved-2 Solutions] Error: Jump to case label
Error Description:
Error: Jump to case label
Solution 1:
- The problem is that variables declared in one case are still visible in the subsequent cases unless an explicit { } block is used, but they will not be initialized because the initialization code belongs to another case.
- In the following code, if foo equals 1, everything is ok, but if it equals 2, we'll accidentally use the i variable which does exist but probably contains garbage.
- Wrapping the case in an explicit block solves the problem:
Solution 2:
- Declaration of new variables in case statements is what causing problems. Enclosing all casestatements in {} will limit the scope of newly declared variables to the currently executing case which solves the problem.