Chapter 16 The Single-Alternative Decision Structure

16.1 The Single-Alternative Decision Structure

This is the simplest decision control structure. It includes a statement or block of statements on the “true” path only, as presented in the following flowchart fragment, given in general form.

Image

If Boolean_Expression evaluates to true, the statement, or block of statements, of the structure is executed; otherwise, the statements are skipped.

The general form of the C++ statement is

if (Boolean_Expression) {
A statement or block of statements
}

Note that the statement or block of statements is indented by 2 spaces.

In the next example, the message ...

Get C++ and Algorithmic Thinking for the Complete Beginner 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.