# Counting Loop Quiz

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make you choice by clicking on its button. You can change your answers at any time. (When the quiz is graded, the correct answers will appear in the box after each question.)

1. What three parts of a counting loop must be coordinated in order for the loop to work properly?

 a. initializing the counter, testing the counter, changing the counter b. initializing the condition, changing the condition, terminating the loop c. the while, the assignment, and the loop body d. the while statement, the if statement, and sequential execution.

2. Another word for "looping" is:

 a. recapitulation b. tintinabulation c. iteration d. reiteration

3. What makes a loop a counting loop?

 a. A loop control variable is tested in the while statement, and is changed each time the loop body executes, b. A counter is counted upwards by one until it hits a particular limit. c. A counter is counted downwards by one until it hits zero. d. No loop control variables are used.

4. Examine the following code:

```    int count = 0;
while ( count <= 6 )
{
System.out.print( count + " " );
count = count + 2;
}
System.out.println(  );
```

What does this code print on the monitor?

 a. 1 2 3 4 5 6 b. 0 2 4 6 8 c. 0 2 4 d. 0 2 4 6

5. Examine the following code:

```    int count = 7;
while ( count >= 4 )
{
System.out.print( count + " " );
count = count - 1;
}
System.out.println(  );
```

What does this code print on the monitor?

 a. 1 2 3 4 5 6 7 b. 7 6 5 4 c. 6 5 4 3 d. 7 6 5 4 3

6. Examine the following code:

```    int count = -2 ;
while ( count < 3 )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println(  );
```

What does this code print on the monitor?

 a. -2 -1 1 2 3 4 b. -2 -1 1 2 3 c. -3 -4 -5 -6 -7 d. -2 -1 0 1 2

7. Examine the following code:

```    int count =  1;
while ( count < 5 )
{
System.out.print( count + " " );
}
System.out.println(  );
```

What does this code print on the monitor?

 a. 1 2 3 4 b. 1 2 3 4 5 c. 2 3 4 d. 1 1 1 1 1 1 1 1 1 1 1 . . . .

8. Examine the following code:

```    int count =  1;
while (  ___________ )
{
System.out.print( count + " " );
count = count + 1;
}
System.out.println(  );
```

What condition should be used so that the code writes out:

```1 2 3 4 5 6 7 8
```

 a. count < 8 b. count < 9 c. count+1 <= 8 d. count != 8

9. Which of the following situation most likely does NOT call for a counting loop?

 a. Adding up all the integers between zero and one hundred. b. Writing out a table of Fahrenheit and Celcius temperature equivalents. c. Prompting the user of a program until the user responds with correct information. d. Making the computer beep ten times.

10. What is the most common type of bug in software?

 a. The "wrong way" problem, where a two way decision is written incorrectly. b. The "wrong operator" problem, where an arithmetic expression does not mean what the programmer thought it did. c. The "unititialized variable" problem, where a variable is used in an expression before its contents have been initialized. d. The "off by one" problem, where a counting loop executes its body one time too many or one time too few.

The number you got right:       Percent Correct:       Letter Grade:

 (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)