revised: 01/17/00; 10/04/03


Quiz on Result-controlled Loops

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 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 are the three types of loops that can be built using the while statement and other statements?

A.    Counting loops, sentinel-controlled loops, result-controlled loops
B.    Increasing loops, decreasing loops, result-controlled loops
C.    if loops, while loops, counting loops
D.    top-driven loops, result-controlled loops, bottom feeder loops

2. Which of the following is most likely to use a counting loop?

A.    Checking that each price in a list of items offered for sale is less than $125.
B.    Asking the user at the end of a game if the user wants to play again.
C.    Checking if a particular integer is even or odd.
D.    Trying various letter substitution combinations until a message in a secret code can be read.

3. Which of the following is most likely to use a sentinel loop?

A.    Checking that each price in a list of items offered for sale is less than $125.
B.    Asking the user at the end of a game if the user wants to play again.
C.    Checking if a particular integer is even or odd.
D.    Trying various letter substitution combinations until a message in a secret code can be read.

4. Which of the following is most likely to use a result-controlled loop?

A.    Checking that each price in a list of items offered for sale is less than $125.
B.    Asking the user at the end of a game if the user wants to play again.
C.    Checking if a particular integer is even or odd.
D.    Trying various letter substitution combinations until a message in a secret code can be read.

5. Here is part of a graphics program that simulates a color fading in the sun. The amount of red starts at the maximum of 1.0 and is faded by drecreasing it by 1% each time the loop executes, until it is close to zero.

      float redLevel = 1.0;
      while (  __________________  )
      {      
         redLevel = redLevel*0.99 ;
 
         // the new redLevel is used here in some graphics methods         
      }

 

Pick a condition for the while statement.

A.    redLevel == 0.0
B.    redLevel > 0.001
C.    Math.abs( redLevel ) < 0.0
D.    redLevel*redLevel < 1.0

6. It is (unfortunately) easy to write a result-controlled loop that tries to reach a goal that is too perfect to be achieved. What happens in this situation?

A.    The program fails to compile.
B.    The program compiles, but won't run.
C.    The program compiles and runs forever.
D.    The program compiles but computes a completely wrong result.

7. When the operating system of a computer writes data to the hard disk, the hard disk is often not ready and does not accept the data. The operating system must repeatedly try to write the data until it is accepted. What kind of loop is this?

A.    Sentinel-controlled.
B.    Counting loop.
C.    Disk-controlled.
D.    Result-controlled.

8. A colony of rabbits doubles its population every 28 days. The population starts out at 2 and increases until it reaches 100,000. Say that a section of code simulated this process. Which of the following while statements is most likely to be used?

A.    while ( population = 10000 )
B.    while ( population < 100000 )
C.    while ( population != 100000 )
d. while ( population < 1.0E+6 )

9. To ensure that a number is positive find its:

A.    actual value
B.    real value
C.    absolute value
D.    mega value

10. Examine the following code fragment:

      int j = 1;
      while (  j < 10  )
      {      
          System.out.print( j + " " ); 
          j = j + j%3;
      }

What is output to the monitor?

A.    1 4 7
B.    1 4 7 10
C.    1 2 5 8
D.    1 2 4 5 7 8

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.