user982209 user982209 - 1 month ago 11
C++ Question

Multiple conditions in switch case?

Can i use switch case to check multiple condition? like for example either or of the condition fulfilled it will do its case?

switch (conditionA or conditionB fullfilled)
{ //execute code }

Answer Source

No. In c++ switch case can be used only for checking values of one variable for equality:

switch (var) {
    case value1: /* ... */ break;
    case value2: /* ... */ break;
    /* ... */
}

But you can use multiple switches:

switch (var1) {
    case value1_1:
        switch (var2) {
            /* ... */
        }
        break;
    /* ... */
}