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

Eunice Torres
Eunice Torres
2,278 Points

Swift for in loop

I can seem to see what this issue is. I have the loop reading the "print()" msg, but it says to make sure all ten print. Which it is...

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

for multiplier in 1...10 {
    print("if the multiplier is \(multiplier), then the multiple is \(multiplier) times 6, which is equal to \(multiplier * 6).")
}

1 Answer

Maria Angelica Dadalt
Maria Angelica Dadalt
6,197 Points

The challenge doesn't ask you to print anything, you only have to append the results of the for-in loop to the results variable.

The loop should look like this:

var results: [Int] = []

for multiplier in 1...10 {
    results.append(multiplier * 6)
}

It's all much simpler than you initially think and you'll eventually get it. It also took me a while to see it. To be honest, sometimes I still feel stumped by what I should do. When I feel stuck, I usually check the Swift guidelines, rewatch the courses, copy all the code the teacher does in the videos, and search community for answers to the challenge I can't get through.

It will start to get easier to understand, I swear! Hope this helps!