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 2.0 Collections and Control Flow - Looping Over Ranges Video trouble

As I'm going through the exercise for Looping over Ranges, where you get Xcode to print a multiplication table of 5, I keep getting errors in the debug panel and can't figure out how my code is different from the instructor. I've gone back over the video twice and just can't seem to figure it out.

Here's my code:

for number in 1...10 { print("(number) times 5 is equal to \ (number * 5)") }

Does anyone see anything that is glaringly wrong here? Xcode just ain't havin none of it. ( :

UPDATE: after some searching, I changed the formatting based on apple's Developer Library to:

for number in 1...10 { print("(number) times 5 is (number * 5)") }

and now the multiplication table is printing fine without errors. My guess is now that the version of Xcode used in the course video is a little older and that's why it would pass for the instructor, but not on my version of Xcode.

Anyone feel free to let me know if I'm wrong, but that's what I'm going to assume for now.

Hey there! I am curious:

The example from your update should not print the actual values, as \() is the way to add dynamic values to strings, so-called string interpolation. So this:

for number in 1...10 {
   print("(number) times 5 is (number * 5)")
}

would actually print ten times (number) times 5 is (number * 5), whereas this

for number in 1...10 {
   print("\(number) times 5 is \(number * 5)")
}

should give you the expected output. Can you confirm?

Cheers Martin

Thanks for looking at it Martin! I think I'm in over my head. Both the updated code and your code produced the same result in my version of Xcode. Here's what is shows in the debugger: 1 times 5 is 5 2 times 5 is 10 3 times 5 is 15 4 times 5 is 20 5 times 5 is 25 6 times 5 is 30 7 times 5 is 35 8 times 5 is 40 9 times 5 is 45 10 times 5 is 50 1 times 5 is 5 2 times 5 is 10 3 times 5 is 15 4 times 5 is 20 5 times 5 is 25 6 times 5 is 30 7 times 5 is 35 8 times 5 is 40 9 times 5 is 45 10 times 5 is 50

It's just crazy train. ( :

Maybe I just have to let this one go? LOL

I'm in Xcode version 7.2.1 if that helps.

PS- how do I make my code look nifty like yours?

I have no clue what kind of magic you are applying, but this is what I get with Xcode 7.3 ;) Swift

To write a code block, use three backticks followed by the language. To end a code block use three single backticks

Swift