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 Collections and Control Flow Control Flow With Loops For In Loops

i dont understand how to ammend the first line of code

var results: [Int] = ?

I am stumped on how to add the for in code on the first line and ammend it to the variable results line of code.

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

1 Answer

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi there,

a short answer to your question: first line should stay first! In the first line, you have a definition of the array that you will need to use later on.

So your line:

for multiplier in 1...10 { multiplier * 6 }

is fine, but should rather go after the array definition and also you don't store your result (multiplier * 6)* anywhere, while you should have something like:

myArray.append(newArrayValue)

So, let's sum it up:

1st part of the challenge, just put 'for-in' definition after the array definition:

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {

}

Then fix loop with your code, but remember to add result at the end of the array (using append method):

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

That's it!

Cheers! Jarek