PREDICT THE OUTPUT OF THE FOLLOWING NESTED LOOPS

37. Predict the output of the following nested loops:int n, m;for (n = 1; n <= 10; n++)for (m = 10; m >= 1; m--) cout << n << " times " << m << " = " << n*m << endl;

Chapter Summary

Boolean expressions are evaluated similar to the way arithmetic expressions are

evaluated.

The C++ branching statements are the

if-else

statement and the

switch

state-

ment.

A

switch

statement is a multiway branching statement. You can also form multiway

branching statements by nesting

if-else

statements to form a multiway

if-else

statement.

A

switch

statement is a good way to implement a menu for the user of your pro-

gram.

The C++ loop statements are the

while

,

do-while

, and

for

statements.

A

do-while

statement always iterates their loop body at least one time. Both a

while

statement and a

for

statement might iterate their loop body zero times.

A

for

loop can be used to obtain the equivalent of the instruction “repeat the loop

body

n

times.”

84 Flow of Control

A loop can be ended early with a

break

statement. A single iteration of a loop body

may be ended early with a

continue

statement. It is best to use

break

statements

sparingly. It is best to completely avoid using

continue

statements, although some

programmers do use them on rare occasions.

A

NSWERSTO

S

ELF

-T

EST

E

XERCISES