19.2.4.  Review Questions

[ fromfile: controlstructures-questions.xml id: controlstructures-questions ]

  1. What is the difference between a compound statement and a simple statement?

      a simple statement is terminated by a ; a compound statement has curly braces {} around a group of simple statements.

  2. How can you guarantee that at least one case will be executed for any given switch value?

      add a default case.

  3. What are the advantages and disadvantages of the three iteration structures? For each, discuss the kinds of situations that would lead you to prefer using it rather than the other two.

      the do..while loop is useful if you want to guarantee that the body is executed at least once. The for loop is useful if you need a counter to be incremented in the loop.