Conditional Statements

Conditional statements are probably the most ubiquitous control construct in C++ programs. You can hardly write a few statements of code without bumping into the need to do something only in the case when some condition holds; otherwise, you would do a different thing.

There are several forms of conditional statements that you can choose from while writing C++ code. Complex forms of conditional statements require diligent testing, but they often provide opportunities for making source code more concise and more elegant.

Standard Forms of Conditional Statements

The C++ conditional statement in its most general form has two branches, the True branch and the False branch. Only one of these branches can be executed when the ...

Get Core C++ A Software Engineering Approach 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.