... 5.9 uses a dowhile to output the numbers 1–10.

Fig. 5.9 dowhile iteration statement.

Alternate View

 1   // Fig. 5.9: DoWhileTest.cpp
 2   // do...while iteration statement.
 3   #include <iostream>
 4   using namespace std;
 5
 6   int main() {
 7      unsigned int counter{1};
 8
 9      do {                                      
10         cout << counter << " ";                
11         ++counter;                             
12      } while (counter <= 10); // end do...while
13
14      cout << endl;
15   }

1 2 3 4 5 6 7 8 9 10

Line 7 declares and initializes control variable counter. Upon entering the dowhile statement, line 10 outputs counter’s value and line 11 increments counter. Then the program evaluates the loop-continuation test at the bottom of the loop ...

Get C++ How to Program, 10/e 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.