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 Looping Over Ranges

Roberto Reynoso
Roberto Reynoso
4,734 Points

I don't quite understand the answer to the challenge.

I thought I understood what I was doing, but the answer to append the results? why is that. Why are we appending the answer.

My original answer was:

var results: [Int] = [1,2,3,4,5,6,7,8,9,10] for multiplier in results { print("(multiplier) times 6 is equal to (multiplier * 6)") }

But the answer:

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

What I don't understand is what is results there for. from what I see results is basically nothing and we append(add) it to the for loop? what good does that do?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Remember that this is a challenge. They are testing your ability to do something using the knowledge you've gained. It's not really meant to be a full-fledged program and in some cases has very limited use at all.

However, down the road, there are use cases for looping through something and appending to a list. What if you had a list with all your favorite songs in it? You might want to loop through that list and make a new list that contains only songs by a certain artist or certain genre and then display the results of the resulting list. This is just an example that comes to mind, but there are many others.

Essentially, the answer is: because they said to do it.

Hope this helps! :sparkles:

Roberto Reynoso
Roberto Reynoso
4,734 Points

Ya it does, thank you for the example I understand why now.