How add “or” in switch statements?

后端 未结 6 1758
离开以前
离开以前 2020-12-24 04:22

This is what I want to do:

switch(myvar)
{
    case: 2 or 5:
    ...
    break;

    case: 7 or 12:
    ...
    break;
    ...
}

I tried wi

6条回答
  •  隐瞒了意图╮
    2020-12-24 04:56

    By stacking each switch case, you achieve the OR condition.

    switch(myvar)
    {
        case 2:
        case 5:
        ...
        break;
    
        case 7:
        case 12:
        ...
        break;
        ...
    }
    

提交回复
热议问题