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 trialMahmoud Rajabzadeh-Mashhadi
489 PointsLoops
It says ... Make sure you are declaring a for in loop. I am not sure what that means. Thanks.
// Enter your code below
struct Tag {
let name: String
}
struct Post {
let title: String
let author: String
let tag: Tag
}
Let b = Tag(name: "name")
let firstPost = Post(title: "title", author: "author", tag: b)"
1 Answer
Steve Hunter
57,712 PointsHi there,
The code you have posted is for a different challenge to the one you have linked to. Which do you need help with?
Your posted code looks OK, bar a stray inverted comma (I've added a comment).
The linked challenge requires you to create a for
loop to iterate over numbers 1 to 10; a range. A range in Swift can be represented by two numbers (the range limits) separated by three dots. So, 1 to 10 looks like 1...10
.
A loop will store each number in the range (one at a time) in a local variable. In this challenge you are asked to use the name multiplier
. As for the loop itself. We start that with the keyword for
then use the local variable name, multiplier
in this case, and say that you are wanting to look in
the range, 1...10
. It will look like:
for multiplier in 1...10{
// code in here happens 10 times
}
I hope that helps!
Steve.