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

append results of for in loop to array

var results: [Int] = []

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

so this is the code, and for test 2 I should take the results of the for in loop and append the results variable. I know how to append variables. but I don't know how to append all the results of that loop to the variable. I don't think the video ever discussed how to append all the results of another line of the code, anyways thats besides the matter. Thanks for any help!!!

mrtroy
mrtroy
8,069 Points

For the above to work the way you want you will need to use:

print("(multiplier) times 6 is equal to (multiplier * 6)")

Or you will get the word instead of the variable. Int's inside of quotes need the back slash.

On step 2 if you add some thing like:

results.append( multiplier * 6 )

You will then call the append method on results and put the times 6 value on the end array.

As an added critique I think you will need to use:

let multiplier: Int

Before that For in Loop

1 Answer

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

Hey! You're on the right track with your for loop, but instead of printing, they are looking for you to implement some of the concepts taught in earlier courses.

You've mentioned that you know how to append, so for this situation, you would replace your 'print' statement with your 'append' statement - your loop should look something like this:

for multiplier in 1...10 {
    results.append( /*insert whatever you want to append here */)
}

Hope that helps!

Yes, that help a lot, thank you!