O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required