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

Dipesh Patel
Dipesh Patel
1,506 Points

I am mis-understanding the question during code challenge?

I am really not understanding the second half of this question....

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

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

This question (which, if I remember correctly, is the second question of this type, the first being the multiple of 5 one) wants you to append the result from the loop into an array as opposed to printing it out.

Dipesh Patel
Dipesh Patel
1,506 Points

correct, i am totally drawing blank on append portion of the array. Ok, after re-reading your response. It doesn't want me to print it. gotcha, thanks!

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points
  1. The challenge is not asking you to print anything; therefore, there is no need for the print statement. It is asking you to append the value to the results array
var results: [Int] = []

for multiplier in 1...10 {

results.append(multiplier * 6)

}
Dipesh Patel
Dipesh Patel
1,506 Points

Thanks! I misunderstood the question and was trapped in the mindset. The comments here helped.

NAVEED CHOWDHURY
NAVEED CHOWDHURY
1,142 Points

Thanks for posting the question Dipesh, it threw me off but now that I look at Jeff's answer its makes sense. You really have to go back and forth between task 1 and 2 to get what the instructor is asking you to do.