Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

2.6. Control Flow Constructs

C++ has constructs that dictate which statements execute, based on the values of expressions. This section introduces C++ constructs and describes how they affect the logic and control flow of programs.

if and if-else

The if construct has three formats. The first format is

if (expression) {
   statements;                 // if-block
}

The expression requires parentheses. If expression evaluates to true, statements execute and control continues with the next statement following the if-block. If expression evaluates to false, control skips to the statement following the if-block. Braces are optional if there is only one statement in the if-block.

The second format is

if (expression) {
   statements1;
}
else {
   statements2;
}

If expression ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book