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

Andrey Mitko
Andrey Mitko
19,127 Points

What?!

Haha, where is my problem? ;)

for_loops.swift
for i in 1...10 {
let i7 = i * 7 
println("\(i) * 7 = \(i7) \n")
}

1 Answer

Hi Andrey,

You're very close - have a look through this:

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

You have the for loop implemented correctly but your handling of the string isn't quite right. I've interpolated \(i) and \(i * 7) and used println to make sure there's a new line inserted. (New swift doesn't use println but the keyword print includes a new line by default).

I think the additional new line was what the compiler was complaining about with your code.

I hope that helps,

Steve.

The error I get with your code is:

 Bummer! You didn't println the right values. You printed [1 * 7 = 7 , 2 * 7 = 14 , 3 * 7 = 21 , 4 * 7 = 28 , 5 * 7 = 35 , 6 * 7 = 42 , 7 * 7 = 49 , 8 * 7 = 56 , 9 * 7 = 63 , 10 * 7 = 70 ], but we were looking for [1 * 7 = 7, 2 * 7 = 14, 3 * 7 = 21, 4 * 7 = 28, 5 * 7 = 35, 6 * 7 = 42, 7 * 7 = 49, 8 * 7 = 56, 9 * 7 = 63, 10 * 7 = 70].

The additional bit of whitespace in between the result of the multiplication and the comma seems to be the issue.

Removing the space and the additional newline caused by the \n and your code is fine.

[EDIT] - no, it is just the \n that's causing the problem.