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

Confused

I don't understand the challenge at all.

What challange is it?

1 Answer

Jayden Spring
Jayden Spring
8,625 Points

A for in loop is a simple enumeration, if you have worked in Javascript or PHP before you would know this as a foreach loop quite simply it will loop through a collection from the first index until the last.

Therefore if you have your array with 10 values it would read something like this

var results : [Int] = [1,2,3,4,5,6,7,8,9,10];

for index in results
{
  print("The value is: \(index)");
}

I suggest having a read through here; https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html

As this is really a fundamental aspect of collection's. Hope this helps.

The only other thing I've used is Python but I still don't really get for in loops.