iOS Swift Collections and Control Flow Control Flow With Loops While and Repeat While

Alex Simons
Alex Simons
1,594 Points

I can't seem to figure out the challege prior to this lesson. Help!!

I found the solution to this challenge but I have no idea how it got there. I would really like for someone to explain it to me

1 Answer

Matthew Long
Matthew Long
28,363 Points
var results: [Int] = []
let multiplier = 6 
for i in 1...10 {
  results.append(6*i)
}

If it was the loop that was giving you trouble then work through the loop yourself. The first time through would be append 6*1 to the results array. The second time would append 6*2 to the results array, etc. Finally you'll have an array with the multiples of 6 from 1 to 10: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. Hopefully, this cleared things up a bit.

Also, if you ask your question while you're on the challenge you'll get a response very quickly, because all people have to do is click 'view challenge' at the top right to see exactly what you're referring to.