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

Valeria Ruiz
Valeria Ruiz
948 Points

Please help, I don't know how to do this step at all :(

hi guys my code is below. As I understand it, I am just missing putting my answers into the original array? But I really don't know . please help me

loops.swift
// Enter your code below
var results: [Int] = [
]
for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

1 Answer

Nathan Tallack
Nathan Tallack
22,160 Points

Good job on the for loop, but a few other things that did not match what the challenge wanted. See your modified code below with comments inline.

// Enter your code below
var results: [Int] = []

let multiplier = 6  // We declare the multiplier tha twe will use in the for loop.

for number in 1...10 {  // We are using number as our iterator variable.
    results.append(number * multiplier)  // We are not printing the result but appending it to the array.
}
Valeria Ruiz
Valeria Ruiz
948 Points

Thanks so much Nathan! I saw your post somewhere else after I posted this question and I didn't understand why our code was so different (obviously yours was the right one)

Thank you so much for the detailed explanation.

Nathan Tallack
Nathan Tallack
22,160 Points

Yeah, it's a tough one. As you can see we all have a problem with it! That's what makes these challenges so great! They really ensure that you understand what you are learning before you can move on. :)

Keep up the great work!!! :D