revised: 10/04/03, 10/29/2012, 07/20/2017


quiz on Counting Loops

Instructions: For each question, choose the single best answer. Make your 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:   


Click here If you have 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 to clear the old answers.