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

Help with Code Challenge

I'm not sure how to approach this code challenge. Can you break it down for me and explain how to solve it?

1 Answer

Paul Brazell
Paul Brazell
14,371 Points

So the challenge prompts you to create a for in loop which will simulate a multiplication table. The first challenge asks you to create the body of the loop with no implementation. This will look something like this:

for multiplier in 1...10 {


The range 1...10 means it will loop ten times including the tenth time.

You then are asked to provide an implementation of the multiplication and append it to the results array. This can be done simply with 1 line of code, or you can separate the calculation and appending. You wouldn't want to put a ton of calculations in the parameter of the append method, but since this is a simple calculation I don't think its an issue.

The end result is this:

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

Thanks so much for your help with this. Everything went smoothly with your instructions and code.