Write two code segments that print the integers 1 through 10. One segment should use a while loop and the other should use a for loop.
What will be an ideal response?
// Declare loop control variable and limit
int x;
const int LIMIT = 10;
// Using a while loop to display 1 through 10
x = 1;
while(x <= LIMIT)
{
WriteLine(x);
++x;
}
// Using a for loop to display 1 through 10
for(x = 1; x <= LIMIT; ++x)
WriteLine(x);
You might also like to view...
In a star topology, the nodes connect to a central communications device called a router.
Answer the following statement true (T) or false (F)
When any primitive type is passed to a method, the ____ is passed.
A. address B. return type C. unsigned value D. value
To count words, click the Word Count indicator on the Home tab to display the Word Count dialog box.
Answer the following statement true (T) or false (F)
Bloom's Taxonomy of cognitive skills includes 6 categories of skill levels from simple behaviors, such as ability to remember facts, to complex skills, such as evaluating information.
Answer the following statement true (T) or false (F)