Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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. :)