Quick Test 9/10: Loops

1. In which type of loop is the instruction executed at least once?

for
while
do-while
Such a loop doesn't exist

2.  We want to write a program that asks the user to supply a number. The program then should show all the prime numbers up to that number. In this case, the best loop to use is

for
while
do-while
Other structure

3. What are the two basic rules for nesting of loops?

1: 
2: 

4. What is the diference between loops of type while and do-while?

while is for integer numbers, do-while is for variables of floating point type.
do-while is for integer numbers, while is for variables of floating point type.
In loops of type do-while the condition is checked in the beginning, whereas in loops of type while the condition is checked at the end.
In loops of type while the condition is checked in the beginning, whereas in loops of type do-while the condition is checked at the end.

5. What is wrong with the following code?
x = 0.0;
while (x<10.0)
  {
    y = x*x;
    z = x*y;
    printf("The square of %f is %f", x, y);
    printf("The cube of %f is %f", x, z);
  }

This loop will never finish
We should use a loop of do-while instead.
We should use a for-loop instead.
The condition cannot contain variables of type float.

6.  We want to write a program that asks the user to choose a type of calculation or to exit the program (1=adding, 2=subtracting, 0=finish). It has to continue doing this forever (except, of course when the user selects 0). In this case, the best loop to use is

for
while
do-while
Other structure