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 2.0 Collections and Control Flow Control Flow With Loops For In Loops

Help me debug my code

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

In iterating over the array, what is wrong with my code? Thanks

4 Answers

Your code:

var results: [Int] = [] 

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

Get rid of let. In a for in loop, the constant multiplier goes between the for and the in. Don't need the x since multiplier is the name used for every item when iterating through the array. Also, results.append() goes inside the for in loop.

My suggestion:

var results: [Int] = []

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

Thank you so much Ella. Very much appreciated.

You're welcome. Happy to help and thanks for the follow.

I actually followed you on linked In. Abdi

Hey Ella, I didn't have any problem wrong with this question, but it helped! Thanks for sharing your knowledge!