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

Loops

I don't know how to do this, "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."

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

2 Answers

Chris Sehnert
Chris Sehnert
30,857 Points

There are (at least) two types of IOS statements that are needed to complete this task...

1.) a "for in loop" is a common control flow mechanism in any computer language...in IOS...the syntax "simplifies" things a bit...once you understand the syntax..."for _____ in _____ {}"...the first blank gets filled with the name you provide to represent the constant value...(this problem specifies that you use "multiplier" for this space....the blank that follows "in" is where you place your range statement representing the number of iterations you require....(in this case 10)...the body of the forIn statement goes inside the {}.....that's where you will use and array.append() method for each iteration....

2.)A Range in IOS allows you to iterate a specified number of times the syntax is either "value-dot-dot-dot-value" like 1...10 (for ten iterations from 1 to 10 inclusive)... or "value-dot-dot-lessThanSymbol-value" as in 1..<11 when you don't want to include the last "value"....(therefore also iterates from 1 to 10)...

harshil bhatt
PLUS
harshil bhatt
Courses Plus Student 2,722 Points

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

for multiplier in 1...10 { let Numbers = multiplier * 6 results.append(Numbers) }