Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.