Error: Jump to case label

后端 未结 4 862
春和景丽
春和景丽 2020-11-27 09:56

I wrote a program which involves use of switch statements... However on compilation it shows:

Error: Jump to case label.

Why doe

4条回答
  •  攒了一身酷
    2020-11-27 10:09

    Declaration of new variables in case statements is what causing problems. Enclosing all case statements in {} will limit the scope of newly declared variables to the currently executing case which solves the problem.

    switch(choice)
    {
        case 1: {
           // .......
        }break;
        case 2: {
           // .......
        }break;
        case 3: {
           // .......
        }break;
    }    
    

提交回复
热议问题