Iteration MCQ Practice

Question 1 of 10

count starts at 0. How many times does DISPLAY run?

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

Question 2 of 10

n starts at 1. What is displayed when the loop finishes?

n ← 1
REPEAT UNTIL (n > 3)
{
  DISPLAY (n)
  n ← n + 1
}
  1. A. Nothing is displayed.
  2. B. 1 2 3
  3. C. 1 2 3 4
  4. D. 2 3 4

Question 3 of 10

k starts at 5. How many times does the body execute?

k ← 5
REPEAT UNTIL (k >= 5)
{
  k ← k + 1
}
  1. A. 5
  2. B. Infinitely many
  3. C. 0
  4. D. 1

Question 4 of 10

total starts at 0. What value is displayed?

total ← 0
REPEAT 3 TIMES
{
  total ← total + 2
}
DISPLAY (total)
  1. A. 8
  2. B. 2
  3. C. 3
  4. D. 6

Question 5 of 10

c starts at 0. Which statement is correct?

c ← 0
REPEAT UNTIL (c = 3)
{
  c ← c + 1
  DISPLAY (c)
}
  1. A. It displays 1 2 3 and stops.
  2. B. It displays 1 2 3 4 and stops.
  3. C. It never stops because c never equals 3.
  4. D. It displays 0 1 2 and stops.

Question 6 of 10

How many robot steps forward occur?

REPEAT 5 TIMES
{
  MOVE_FORWARD
}
  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 0

Question 7 of 10

x starts at 2. What is the final value of x?

x ← 2
REPEAT UNTIL (x >= 10)
{
  x ← x * 2
}
  1. A. 8
  2. B. 10
  3. C. 16
  4. D. 2

Question 8 of 10

t starts at 1. Loop: REPEAT UNTIL (t > 4) { t ← t + 1 }. Sequence of t values right after each body run until stop?

Check Body?
t > 4? runs if false
  1. A. 1, 2, 3, 4
  2. B. 3, 4, 5
  3. C. 2, 3, 4
  4. D. 2, 3, 4, 5

Question 9 of 10

sum starts at 0 and i starts at 1. What is displayed?

sum ← 0
i ← 1
REPEAT UNTIL (i > 4)
{
  sum ← sum + i
  i ← i + 1
}
DISPLAY (sum)
  1. A. 10
  2. B. 15
  3. C. 4
  4. D. 6

Question 10 of 10

Which loop is guaranteed to run its body exactly 7 times?

  1. A. REPEAT UNTIL (true) { ... }
  2. B. REPEAT 7 TIMES { ... }
  3. C. REPEAT UNTIL (count = 7) { count ← count + 1 } when count starts at 7
  4. D. REPEAT UNTIL (false) { ... }