Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,407 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.