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

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 { }