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

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?
2:What is the output from the following piece of source code? (Mentally trace the code.)
int counter = 0;
while(counter < 4)
{
    counter++;
    Console.Write(counter + " ");
}
3:What is the output from the following do-while construct? (Trace the code.)
int counter = 4;
do
{
    Console.Write(counter + " ");
    counter--;
} while(counter > 0);
Console.WriteLine("Value of counter: {0} ", counter);
4:What is the output from the following for loop construct? (Trace the code.)
for(int i = 0; i < 0; i += 2)
{
    Console.Write(i + " ");
}
5:Write a for loop that generates the following output:

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