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

Brian Uribe
Brian Uribe
3,488 Points

Code isn't working

I've basically copied the code from the video and it still isn't working. What is going on?

loops.swift
var results: [Int] = [1...10]

for multiplier in 1...10 {
  Print("\(multiplier) times 6 is equal to \(multiplier *6)")
}

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Brian Uribe,

The challenge is asking you to append the value of multiplier * 6 for a range of 1 through 10 to the results array. What you need to use is the for loop and the append() method.

/* we just initialize this array and don't put any values in it,
later we are going to store the output from our loop here */
var results: [Int] = []

/* this will loop over the values 1 through 10 and assign each one
to a temporary constant named multiplier */
for multiplier in 1...10 {

/* now for each iteration of the loop (each case of multiplier),
we will multiply it by 6 and append it to the array results */
results.append(multiplier * 6)


}

Hope this helps!