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-elsestatement and the
switchstate-
ment.
■
A
switchstatement is a multiway branching statement. You can also form multiway
branching statements by nesting
if-elsestatements to form a multiway
if-elsestatement.
■
A
switchstatement 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
forstatements.
■
A
do-whilestatement always iterates their loop body at least one time. Both a
whilestatement and a
forstatement might iterate their loop body zero times.
■
A
forloop can be used to obtain the equivalent of the instruction “repeat the loop
body
ntimes.”
84 Flow of Control
■