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

Cannot compile/Append the array

I am having difficulty trying to append the array. The first part of the challenge I can figure out, but I am not sure on two things. How am I telling it "Pull 1-10 as the range to multiply by". When I insert numbers in to the array it doesn't seem to like that. Anyone have any input or a proper solution so I can see how it is done?

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

for multiplier in results {

    results.append(multiplier*6)
}

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Justin Cruz,

You're almost there! Just one thing to clear up. You can't iterate over the results array in your for loop because it is empty. Instead of results, this is where you put the range you were curious about. Take a look at my code below:

var results: [Int] = []

/* This for loop takes the range of 1...10
Then for each iteration of the loop, it
assigns a number 1 through 10 to
the temporary constant multiplier. */

/* Each time the loop completes, it will
get the next number in the range and
update multiplier */

/* So the first time the loop runs:
multiplier = 1
The next time
multiplier = 2
The next time
multiplier = 3
All the way until the range is complete (10) */

for multiplier in 1...10 {
    /* this will add the value of multiplier * 6,
    to the results array, then start the loop again */
    results.append(multiplier*6)
}

Hope this helps! Good Luck!

UGHGHGHGH!! No wonder I wasn't getting it! I kept wondering "Where the hell is it going to pull the sequence from". Thanks for the assist Steven.