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:

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.