switch statement

is the switch a loop, a conditional, or a subroutine construct or all of the above, or none of the above
A switch is a decision construct, but I would argue that it's not a conditional construct, because there are expressions involving == that cannot be mapped to a switch.
1
2
3
4
5
6
7
8
9
10
std::string s = "hello";
// Valid:
if (s == "hello"){
}

// Invalid:
switch (s){
    case "hello":
        break;
}
closed account (48T7M4Gy)
A switch is a selection statement and is 'none of the above'.
http://www.cplusplus.com/doc/tutorial/control/
http://en.cppreference.com/w/cpp/language/switch
Last edited on
Topic archived. No new replies allowed.