June 2025
Intermediate to advanced
1093 pages
33h 24m
English
You have already seen that you can use if-else cascades to check multiple cases in succession. The switch statement is a specialized form of the case where you always test the same expression, and the expression has an int-like type—or is an enum, as you will see in Chapter 16, Section 16.12.2:
switch( Expression ) { Cases }
Since C++17, it works analogously to if as well:
switch( Initialization ; Expression ) { Cases }
Where Cases consist of a sequence of cases of the following form:
case Constant: Statements
From the list of Cases, those Statements are executed whose Constant matches the result of the Expression. There are still some things to consider or that are worth knowing:
Cases must not contain duplicate ...
Read now
Unlock full access