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

help me please i dont understand?

help me

loops.swift
// Enter your code below
var results: [Int] = []
for multiplier in 1...10{
    print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}
var results: [Int] = []
for multiplier in 1...10{
    results.append(multiplier*6)
}

1 Answer

Nils,

What this For-In Loop is doing is taking our number and assigning it a number 1 through 10. Each time multiplying that number by 6 and printing it out.

for number in 1...10{
    print("\(number) times 6 is equal to \(number * 6)")  // number * 6
}

1 times 6 is equal to 6 2 times 6 is equal to 12 3 times 6 is equal to 18 4 times 6 is equal to 24 5 times 6 is equal to 30 6 times 6 is equal to 36 7 times 6 is equal to 42 8 times 6 is equal to 48 9 times 6 is equal to 54 10 times 6 is equal to 60