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

Emma Renteria
Emma Renteria
476 Points

Swift 3 collections and control flow Challenge 1 of 2:

For this challenge, we're going to use a for in loop to compute the multiplication table for 6 and append the results to an array.

Your task for this first step is to create a for in loop that iterates over a range. Multiplication tables typically range from 1 to 10 (with 10 included) so the range you are iterating over should go from 1 to 10. Note: Leave the body of the loop empty for this task.

For in loops also define a constant that temporarily stores the value in the iteration process. For the loop you're writing, name this constant multiplier.

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
("\(number) times 6 is equal to \(number * 6)")

1 Answer

Hi Emma,

At this stage, your loop should be blank - in the next task, you'll write to the array but you won't use a string like that.

The reason the compiler is griping is that you've used the variable name number when that doesn't exist within your code.

You can switch it to multiplier and the task will pass, but that line of code remains unnecessary at this point and can be omitted.


No need to delete, Gabriel!