Quick Test 10/11: Loops

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

For
While-Do
Repeat-Until
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
Repeat-Until
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-Do and Repeat-Until?

While-Do is for integer numbers, Repeat-Until is for variables of floating point type.
Repeat-Until is for integer numbers, While-Do is for variables of floating point type.
In loops of type Repeat-Until the condition is checked in the beginning, whereas in loops of type While-Do the condition is checked at the end.
In loops of type While-Do the condition is checked in the beginning, whereas in loops of type Repeat-Until the condition is checked at the end.

5. What is wrong with the following code?
x := 0.0;
while (x<10.0) do
  begin
    y := x*x;
    z := x*y;
    writeln('The square of ',x:0:2, ' is ', y:0:2);
    writeln('The cube of ',x:0:2, ' is ', z:0:2);
  end;

This loop will never finish
We should use a loop of Repeat-Until instead.
We should use a For-loop instead.
The condition cannot contain variables of type real.

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
Repeat-Until
Other structure