Back

Question Set 3

Six questions · 10 minutes · cumulative through 1.17

divider

What This Is

Six exam-style questions, weighted toward iteration. Four of them ask you to count passes, which is exactly what the exam's written questions do.

Set a timer for 10 minutes. On paper, no computer. Write out the passes in a column rather than doing them in your head — four rows is usually enough to see the answer, and it is faster than being wrong.


The Questions


Question 1

What does this print?

Lua
local w = 10
local steps = 0
while w > 0 do
w = w - 4
steps = steps + 1
end
print(steps)
  • (A) 2
  • (B) 3
  • (C) 4
  • (D) It never ends

Question 2

What does this display?

Exam notation
x ← 5
passes ← 0
REPEAT UNTIL(x > 10)
{
passes ← passes + 1
x ← x + 1
}
DISPLAY(passes)
  • (A) 5
  • (B) 6
  • (C) 10
  • (D) 0

Question 3

What does this print?

Lua
local c = 0
for i = 3, 7 do
c = c + 1
end
print(c)
  • (A) 4
  • (B) 5
  • (C) 7
  • (D) 3

Question 4

What does this print?

Lua
local hits = 0
for row = 1, 4 do
for col = 1, 3 do
hits = hits + 1
end
end
print(hits)
  • (A) 7
  • (B) 4
  • (C) 12
  • (D) 3

Question 5

On the exam reference sheet, REPEAT n TIMES:

  • (A) Provides a counter variable you can use in the body
  • (B) Provides no counter; you make one by hand if you need it
  • (C) Is the same as REPEAT UNTIL(n)
  • (D) Runs at least once even when n is 0

Question 6 — select all that apply

Which of these can run their body zero times?

  • (A) while in Lua
  • (B) repeat … until in Lua
  • (C) for i = 1, n do in Lua, when n is 0
  • (D) REPEAT UNTIL(condition) on the exam

Option D is the one worth thinking hardest about. The exam shares a word with Lua here and does not share the timing.


Submit

Six answers with sure or unsure beside each, and your time. For question 6, list every letter you chose.

Attach your pass tables for questions 1 to 4. The working is worth more than the answer, and on the exam it is what stops a careless slip.

Worth 4 points, graded on completion.

Start the Timer