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

Michael Hodges
Michael Hodges
10,826 Points

"7 times table"

I keep getting an error that my code is incorrect, and i'm pretty sure it's not. The resulting output should be:

1 * 7 = 7 2 * 7 = 14 etc all the way to 10.

Here is my code:

for number in 1...10 {
  println("\(number) * 7 = \(number*7)\n")
}

I even finally just pasted the code into Xcode and it printed the result I'm supposed to get. Am I missing something here?

2 Answers

Everything looks fine, just get rid of the newline character. Println already goes down to the next line, after it finishes it's execution. What you're doing is equivalent to pressing enter twice at the end of a sentence.

Michael Hodges
Michael Hodges
10,826 Points

Yep that did it, thanks!

The quiz said "each line should be on a new line" and I guess I just instinctively thought to make sure I add it then, taking it from C's printf. Just going back now and looking at the output in Xcode I guess I should have noticed the double spacing between the results as a clue. :)