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

Sean Lafferty
Sean Lafferty
3,029 Points

PLease help, done understand this!

look at my code and help please

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

for multiplier in 1...10 {


    (multiplier * 6)


}

3 Answers

Hi Sean,

You've got this!

You want to add your multiplier * 6 into the results array. Use the .append() method on results (use dot notation) and include your expression, multiplier * 6 inside the parentheses.

Make sense?

Steve.

Sean Lafferty
Sean Lafferty
3,029 Points

I worked it out finally!, Thanks for your help Steve, you're a hero!

:+1: Good work! :smile:

Sean Lafferty
Sean Lafferty
3,029 Points

No, Im trying that And its still not working :(

I am now doing this -

var results: [Int] = []

for multiplier in 1...10 {


    (multiplier * 6)


}

results.append() = (multiplier * 6)

OK - if you move your append line inside the loop's braces, it'll work fine. You just want one line in there. You call append on results by using dot notation, as you have done. However, inside the brackets after the append word, put what you want to add into the array, which is multiplier * 6; like this: results.append(multiplier * 6). That's all you need inside your loop.

What's happening here is that multiplier will hold each value in your range, one at a time; so, 1, then 2, 3, etc.

So at each point in the loop, you're appending multiplier * 6 into the results array. At the end of the loop, results will hold [6, 12, 18, etc ]. So, you must do the appending inside the loop. The loop will contain only that line.

Steve.