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 Collections and Control Flow Control Flow With Loops For In Loops

D H
D H
496 Points

What to add in result brackets?

Hi, Not 100% what is supposed to go in the results brackets to stop the loop or whether the what i have added to 'for multiplier' is correct?

Challange is :

For this challenge, we're going to use a for in loop to compute the multiplication table for 6 and append the results to an array.

Your task for this first step is to create a for in loop that iterates over a range. Multiplication tables typically range from 1 to 10 (with 10 included) so the range you are iterating over should go from 1 to 10. Note: Leave the body of the loop empty for this task.

For in loops also define a constant that temporarily stores the value in the iteration process. For the loop you're writing, name this constant multiplier.

loops.swift
// Enter your code below
var results: [Int] = []

for multiplier in 1...10 {
("\(multiplier * 6)")

}

1 Answer

Ben Thompson
Ben Thompson
1,430 Points

What you have should be perfect to get your through the first task. Then for the second part, you just need to append the results of the multiplication to the results array.

results.append(multiplier * 6)

That's all you should need in the body of the for in loop, because by specifying the range "1...10", it knows when to stop looping.