switch Statement in C++ — a practical guide to C++ switch statement with clear examples you can reuse in real projects.
C++ Tutorial Series (27/111). Prefer one article? Read the complete C++ tutorial.
Short description
C++17+ supports init-statements in switch; C++17+ also has if with initializer.
switch
switch (op) {
case '+':
result = a + b;
break;
default:
std::cerr << "unknownn";
}