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

Bethel Loh
Bethel Loh
477 Points

Swift 3 collections and control flow: coding challenge for in loop

Hi everyone,

Does anyone know the exact code to get through this challenge?

Cheers

loops.swift
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]
for multiplier in 1...10{
    results.append(multiplier * 6)
}
Eunice Torres
Eunice Torres
2,278 Points

var results: [Int] = []

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

Do not add the integers in the variable since this is done in the loop.

2 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

You do not need to add anything to the code that was provided for the task. Just leave it the way that it is and your code will pass and is correct

var results: [Int] = []

for multiplier in 1...10 {

results.append(multiplier * 6)
}
Jenny Dogan
Jenny Dogan
4,595 Points

Can you explain the logic of declaring the results variable first then performing the math? Also, do you not use interpolation here because multiplier is also an integer? Thanks!

Jeff McDivitt
Jeff McDivitt
23,970 Points

The results variable is just an empty array to hold the multiplier times 6. Also you are correct as you don't need string interpolation because you are not dealing with a string