How do you have logical or in case part of switch statment?

后端 未结 5 1877
小鲜肉
小鲜肉 2021-01-14 15:21

If you have a switch statement and want certain code to be run when the value is one value or another how do you do it? The following code always goes to the defaul

5条回答
  •  旧时难觅i
    2021-01-14 15:47

    Let the switch fall-through:

    switch(x)
    {
        case 2:
        case 5:
            cout << "here I am" << endl;
            break;
        default:
            cout << "no go" << endl;
    }
    

提交回复
热议问题