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

What is wrong with this

What is wrong with this

loops.swift
// Enter your code below
var results: [Int] = [6]

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! There's not much wrong with it at all except that you've started the array with a number already in it. This means that the array Treehouse is looking at now has one extra 6 in it. Erase the first 6 in the array declaration and your code passes!

Happy coding! :sparkles:

Thank you Jennifer for your time. One question thou what is the EXACT purpose of an for in loop? (is it to write out the array or is it to create the array

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Jack Potter that depends entirely on what you're going to do with for in loop. In this particular case, we're going through a range of numbers 1 to 10. So it starts at one and goes to 10. The first time through it the multiplier is at 1 and we multiply that by 6 and add it to our empty array. So at the end of this loop our once empty array will look like this [6, 12, 18. 24, 30, 36, 42, 48, 54, 60].

I hope this helps! :sparkles: