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.

Then again, they just might.

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 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.println( 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 to go back to the main menu.