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

Ricardo Gonzalez
Ricardo Gonzalez
2,286 Points

Don't know what to do what it is asking me for.

It's asking me for a certain task that i am not too sure how to accomplished.

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

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Ricardo,

The challenge wants you to output:

1 * 7 = 7
2 * 7 = 14
3 * 7 = 21
4 * 7 = 28
...

You're very close. In fact your code works - it will just output this:

1 * 7 =
2 * 14 =
3 * 21 =
4 * 28 =
...

If you tweak your code just a bit, it will output the text above:

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

See the difference? It's important you understand why the answer is right, and not just copy and paste the solution in. Otherwise, you'll run into more trouble down the line :).

Good luck!

You're on the right track, it's asking you to iterate n times with a for-in loop, and each time, print out a message to the console that interpolates 'i' into the phrase in two different ways.