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

Raphael Reiter
Raphael Reiter
6,820 Points

second challenge control flows stuck

i am stuck ... i don't get what the task is on this second question of the challenge...

loops.swift
// Enter your code below
var results: [Int] = []

12 Answers

Hi Raphael,

First, you're asked to put a for|in loop together using the variable multiplier as its index.

The loop should iterate from 1 to 10; a range.

for multiplier in 1...10{

}

That's step one. The next part asks you to append the multiplication of the multiplier by 6 into the array declared at the outset.

So, inside your loop, add:

results.append(multiplier * 6)

I hope that helps.

Steve.

Task 1: Create a for in loop that iterates over a range from 1 to 10. Name the temporary constant "multiplier".

for multiplier in 1...10 {
}

Task 2a: Use multiplication to get the multiples of 6 from the loop

for multiplier in 1...10 {
multiplier * 6
}

Task 2b: Append it to the given array "results"

for multiplier in 1...10 {
results.append(multiplier * 6)
}
Raphael Reiter
Raphael Reiter
6,820 Points

thanks guys, i got it now. :)

Souleymane Coulibaly
Souleymane Coulibaly
3,982 Points

Why isn't my code not working?(For in loops Task 2 of 2) var results: [Int] = [1,2,3,4,5,6,7,8,9,10] for multiplier in 1...10 { results.append(multiplier * 6) }

You explicitly stated values in your array. Leave the array empty. Your answer will provide 20 values in your array, 1-10 ( the values you stated) and the for in calculated values. For the challenge, you only want the for in values. Empty the results array and your code will work.

var results: [Int] = []

You're welcome * 8