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

At the For In Loops Objective

In the objective I wrote:

var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for multiplier in results { results.append(multiplier * 6) } results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) results.removeAtIndex(0) print(results )

is there a better way of doing this?

1 Answer

Hello Gustav,

Let me guide you through the process.

A For In statement will loop through an entire range. In this case your objective is to "loop" through 1 to 10, and multiply each number times 6.

You can loop thru a range by simply stating:

for valueGoesHere in 1...10 {
}

Checking your code you are trying to loop the results array- instead you should loop 1...10 and then append to results as you did. As well you should leave the array empty (the objective is to append the results to it).

Code below, hope now you understand :)

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