Chapter 5

1: What's the difference between an entry-condition loop and an exit-condition loop? Which kind is each of the C++ loops?
A1: An entry-condition loop evaluates a test expression before entering the body of the loop. If the condition initially is false, the loop never executes its body. An exit-condition loop evaluates a test expression after processing the body of the loop. Thus, the loop body is executed once even if the test expression initially is false. The for and while loops are entry-condition loops, and the do while loop is an exit-condition loop.
2: What would the following code fragment print if it were part of a valid program?
int i;
for (i = 0; i < 5; i++)
      cout << i;
      cout << "\n";
A2: It would print the following:
 01234  ...

Get C++ Primer Plus, Fourth Edition 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.