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

Ricardo Gonzalez
Ricardo Gonzalez
2,286 Points

How do I add the for in loop to the variable results?

Don't know how to finish challenge.

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

1 Answer

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

You've set up your for loop just fine! However, the challenge doesn't ask you to print anything. They want you to take multiplier and multiply it by 6 then put that into the results array. So the end result array will contain 6, 12, 18, 24, 30, 36, 42, 48, 54, 60. Here's how I did it:

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

They set up the results array for you. Your job is simply to take the result of 6 * multiplier and put it in the array. Hope this helps!