Chapter 7: Advanced Control Flow I

Chapter Goals

Multiple Alternatives

Multiple Alternatives (Coins Flowchart)

Multiple Alternatives (coins6.cpp)

Multiple Alternatives (richter.cpp)


Nested Branches

        The two-level decision process is reflected in two levels of if statements.

Nested Branches (tax.cpp)


Boolean Operations


 The && and || operators are computed using lazy evaluation.

DeMorgan's Law


The for Loop

Syntax 7.1: for Statement

Syntax 7.1 : for Statement

for (initialization_expression; condition; update_expression) statement
Example:
for (int i = 1; i <= 10; i++) sum = sum + i;
Purpose: Execute the initialization statement. While the condition remains true, execute the statement and update the expression.

The for Loop (forfac.cpp)