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

kelly jewkes
kelly jewkes
1,765 Points

Not sure what to append for this code challange?

I can't figure out what I need to append her to results? I've watched the vids a few times, and am reading over "big nerd ranch guide". Just hung up on this. Thanks for any help.

-Question is asking me to append the value of the loop.

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

for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

results.append

1 Answer

Everton Carneiro
Everton Carneiro
15,994 Points

The purpose of the challenge is to append elements to the array 'results' looping through a range from 1 to 10 multiplying each element per 6. In this case, you don't need to print the results. Print are useful to do some checks before actually do the job. But for this work, you need to create an array with the elements found by you. You need to use the append method inside the for loop, otherwise, you can't append each element of the range 1...10 and then multiply the element by 6.

for multiplier in 1...10 {
    results.append(multiplier*6)
}
kelly jewkes
kelly jewkes
1,765 Points

Thank you! That helped a lot. Wasn't sure on the purpose of "print" (very new to this). Thanks again.