Basic Program Control 145
6
- Is it true that a whilestatement can be used and still get the same results as coding
aforstatement? - What must you remember when nesting statements?
- Can a whilestatement be nested in a do...whilestatement?
- What are the four parts of a forstatement?
- What are the two parts of a whilestatement?
- What are the two parts of a do...whilestatement?
Exercises ........................................................................................................
- Write a declaration for an array that will hold 50 type longvalues.
- Show a statement that assigns the value of 123.456to the 50th element in the array
from exercise 1. - What is the value of xwhen the following statement is complete?
for (x = 0; x < 100, x++) ; - What is the value of ctrwhen the following statement is complete?
for (ctr = 2; ctr < 10; ctr += 3) ; - How many Xs does the following print?
for (x = 0; x < 10; x++)
for (y = 5; y > 0; y--)
puts(“X”); - Write a forstatement to count from 1 to 100 by 3s.
- Write a whilestatement to count from 1 to 100 by 3s.
- Write a do...whilestatement to count from 1 to 100 by 3s.
9.BUG BUSTER:What is wrong with the following code fragment?
record = 0;
while (record < 100)
{
printf( “\nRecord %d “, record );
printf( “\nGetting next number...” );
}
10.BUG BUSTER:What is wrong with the following code fragment? (MAXVALUESis
not the problem!)
for (counter = 1; counter < MAXVALUES; counter++);
printf(“\nCounter = %d”, counter );
10 448201x-CH06 8/13/02 11:20 AM Page 145