Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!