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

Ken Gerlinger
Ken Gerlinger
2,898 Points

How can I append the results of a loop into a var ?

In can't find a way to store the data of the loop "multiplier" in the var "results". Please help me.

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

for multiplier in 1...10 { print("\(multiplier * 6)")}

results.append("\(multiplier)")

2 Answers

Mathieu St-Vincent
Mathieu St-Vincent
9,244 Points

You're welcome. If the answer did satisfy you, please mark it as answered :)

Mathieu St-Vincent
Mathieu St-Vincent
9,244 Points

You need to insert the results.append inside the loop, and include only the value of the variable instead of the string value.

Also, the challenge does not require you to print anything.

var results: [Int] = []

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