The if else if else
Construction
Computer programs, like life, might present you with a choice of more than two selections. You can extend the C++ if else
statement to meet such a need. As you’ve seen, the else
should be followed by a single statement, which can be a block. Because an if else
statement itself is a single statement, it can follow an else
:
if (ch == 'A') a_grade++; // alternative # 1else if (ch == 'B') // alternative # 2 b_grade++; // subalternative # 2a else soso++; // subalternative # 2b
If ch
is not 'A'
, the program goes to the else
. There, a second if else
subdivides that alternative into two more choices. C++’s free formatting enables you to arrange these ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.