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 trialBethel Loh
477 Pointswhat is the code for the body of this for in loop? cheers
what is the code for the body of this for in loop?
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]
for multiplier in results {
}
3 Answers
Steve Hunter
57,712 PointsHi there,
You've got the correct syntax for the loop. However, you're not iterating over results
, and nor are you populating results yet.
You want to iterate over a range of 1 to 10. Ranges are defined by separating their lower and upper bounds with three full stops. You want 1...10
.
for multiplier in 1...10{
}
And set results
back to an empty array.
I hope that helps,
Steve.
Bethel Loh
477 PointsThanks Steve.
How would you iterate over results and populate the results?
Steve Hunter
57,712 PointsHi Bethel,
You don't need to iterate over results
. The question asks Your task for this first step is to create a for in loop that iterates over a range.. The purpose of the challenge is to populate the array with a 6 times table.
In the second task, you'll be asked to perform a bit of maths at each loop iteration and append that result into results
. You'd use the .append()
method on the array and pass the mathematical expression into it as a parameter.
Steve.