Iteration MCQ Practice

Question 1 of 10

count starts at 0. What is displayed after the loop?

count ← 0
REPEAT 2 TIMES
{
  count ← count + 5
}
DISPLAY (count)
  1. A. 5
  2. B. 7
  3. C. 10
  4. D. 2

Question 2 of 10

j starts at 0. How many times is DISPLAY executed?

j ← 0
REPEAT UNTIL (j >= 4)
{
  j ← j + 1
  DISPLAY ("tick")
}
  1. A. 5
  2. B. 0
  3. C. 3
  4. D. 4

Question 3 of 10

r starts at 1. What values are displayed?

r ← 1
REPEAT UNTIL (r = 1)
{
  DISPLAY (r)
  r ← r + 1
}
  1. A. Nothing is displayed.
  2. B. Infinitely many values
  3. C. 1
  4. D. 1 2

Question 4 of 10

n starts at 9. Final n?

n ← 9
REPEAT UNTIL (n < 5)
{
  n ← n - 2
}
  1. A. 4
  2. B. 3
  3. C. 9
  4. D. 5

Question 5 of 10

How many left rotations?

REPEAT 3 TIMES
{
  ROTATE_LEFT
}
  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 4

Question 6 of 10

a starts at 0, b at 5. Final a?

a ← 0
b ← 5
REPEAT UNTIL (a >= b)
{
  a ← a + 2
}
  1. A. 0
  2. B. 4
  3. C. 5
  4. D. 6

Question 7 of 10

s starts at 4. What is printed?

s ← 4
REPEAT UNTIL (s <= 1)
{
  DISPLAY (s)
  s ← s - 1
}
  1. A. 4 3 2
  2. B. 4 3 2 1 0
  3. C. 3 2 1
  4. D. 4 3 2 1

Question 8 of 10

q starts at 2. Body executions for REPEAT UNTIL (q > 2) { q ← q + 1 }?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. Infinitely many

Question 9 of 10

total starts at 1. DISPLAY shows?

total ← 1
REPEAT 4 TIMES
{
  total ← total * 2
}
DISPLAY (total)
  1. A. 4
  2. B. 8
  3. C. 16
  4. D. 32

Question 10 of 10

w starts at 7. Does the body run?

w ← 7
REPEAT UNTIL (w < 10)
{
  w ← w + 1
}
  1. A. Yes, infinitely many times.
  2. B. Yes, seven times.
  3. C. Yes, once.
  4. D. No; the ending condition is already true.