Chapter 9

Answers to Chapter 9 Review Questions

1: What is the major difference between the while and the do-while statements? Why is the while statement most often the preferred type of statement?
A1: The while statement is an entry condition loop statement; the do-while is an exit condition loop statement. The entry condition loop may never be executed, whereas the do-while condition will be executed at least once. The entry condition loop is better suited to generate and traverse data sequences because perhaps the expected set of data is empty or perhaps no data should be generated in a particular run of the program.
2: What is the output from the following piece of source code? (Mentally trace the code.)
 int counter = 0; while(counter < 4) ...

Get C# Primer Plus now with O’Reilly online learning.

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