Unit 5 Assessment 1 Question 9


#1

The answer to question 9 is “C”, however the for-loop in the question repeats until “i < 4”, so the loop repeats 3 times. How can the answer be C which requires the loop to repeat 4 times? Please let me know what I’m missing. Thanks in advance.


#2

@christinarconnor

var i = 0 so the variable count starts at 0 with the first iteration. With each iteration 1 is added to the count, so the count goes 0, 1, 2, 3.

I’ve attached a screenshot. Hopefully it helps.


#3

Thanks. After thinking it through I guess the best way to explain it to students is that the “counter” doesn’t tick “1” until after having run the function the first time. Appreciate the reply.


#4

Glad I could help! :smiley: