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 Comparison and Logical Operators

Kulan Kahadugoda
Kulan Kahadugoda
2,149 Points

Why is there a slash before the "(distance)" in the if statement?

He never explains why there's a slash in the if statement.

1 Answer

Brenden Konnagan
Brenden Konnagan
16,858 Points

Hello Kulan!

Are you referring to this:

println("\(distance)....")

If so... the syntax you see there is called String Interpolation.

String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash.

Check out "The Swift Programming Language" from Apple for additional documentation.

I hope this helps!

Kulan Kahadugoda
Kulan Kahadugoda
2,149 Points

It did! Thanks!

That was a crystal clear explanation. Thank you for your help.