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 For In Loops

Please I need help solving part 2

Please advise me as to what I am missing.

loops.swift
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]

let multiplier = 6 

for multiplier in 1...10{
        results.append(multiplier * 6)
}

1 Answer

Magnus Hållberg
Magnus Hållberg
17,232 Points

The results array should be empty at start, the append method inside the body of the loop is supposed to do that job. Also delete the multiplier constant you created and you should be good to go. When creating a for loop you automatically get a variable with the job of carrying the value of the range for each iteration, in this case it's named multiplier. Multiplier will at first have the value 1, then 2 and so on. Maybe I'm kicking in open doors for you, if so I'm sorry for over explaining things.

var results: [Int] = []
for multiplier in 1...10 {
  results.append(multiplier * 6)
}

Thank you very much. That was very helpful.