Exercises

  1. 5.5 Describe the four basic elements of counter-controlled iteration.

  2. 5.6 Compare and contrast the while and for iteration statements.

  3. 5.7 Discuss a situation in which it would be more appropriate to use a dowhile statement than a while statement. Explain why.

  4. 5.8 Compare and contrast the break and continue statements.

  5. 5.9 (Find the Code Errors) Find the error(s), if any, in each of the following:

    1.  

      
      For (unsigned int x{100}, x >= 1, ++x) {
         cout << x << endl;
      }
      
    2. The following code should print whether integer value is odd or even:

      
      switch (value % 2) {
         case 0:
            cout << "Even integer" << endl;
         case 1:
            cout << "Odd integer" << endl;}
      
    3. The following code should output the odd integers from 19 to 1:

      
      for (unsigned int ...

Get C++ How to Program, 10/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.