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 Basics (retired) Control Flow For-In Loop

Todd Darling
Todd Darling
1,087 Points

I put the "\n" inside the quotes for the newline character, but it won't compile. It compiled in the playground.

I had the following code:

for number in 1...7 {
  println("\(number) times 7 is \(number * 7)\n")
}

which I tested and ran fine in the Xcode playground and would not compile in the editor here. Am I missing something? I've tried it several different ways (moving the "\n" outside the quotes, to the beginning of the statement, etc.

2 Answers

William Crawford
William Crawford
4,319 Points

I am borrowing this from Stone Preston's answer to a similar question in the Forum: "Remove the new line character from the end. since you are using the println function everything will be on a separate line regardless."

for number in 1...10 {
    println ("\(number) * 7 = \(number*7)")
}
Jeremy Hayden
Jeremy Hayden
1,740 Points

Hi Todd,

The in class editor checks for exact duplication of the anticipated answer. So even though you code works, it's not what the test was asking for.

First, get rid of the \n.

Second the question for the test was to make it in the following format "1 * 7 = 7" Can you see the difference in your output and what would the output would be in William's code above?

Hope this helps.