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 2.0 Collections and Control Flow Control Flow With Loops For In Loops

Dave Hanna
PLUS
Dave Hanna
Courses Plus Student 2,969 Points

Not sure how to get started on this challenge

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.

To start off, I've created an empty array of type Int and assigned it to a variable named results. Note that we have to explicitly declare the type here so that the compiler knows this array will hold Int values.

Your task for this 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.

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.

2 Answers

Hi Dave,

You'd want to start by making a for-in statement. The Challenge tells you that you'll be going over a range of 1 to 10, and to define a constant to temporarily store the value while iterating, and to call that constant 'multiplier'.

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
}

This would pass the first step of the challenge. For the second step, it asks that you multiply that multiplier by 6 and append the result to the results list. So in your code block (which is empty for the first step), you'd add the multiplication and append steps that will be taken with each iteration.

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

for multiplier in 1...10 { }