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


Ben Masel
Ben Masel
2,004 Points

I Need Loops To Be Simplified For Me, Can Any One Help Me?

I Need Loops To Be Simplified For Me. I'm sorry of this is too specific but my head hurts every time i try to understand " for (name) in (array) { statements } ". Can any one help?

1 Answer

Hey, Benjamin

for in loops are now mandatory in the newest version of Swift, because the old-fashioned for i=0;i<x;i++ method is deprecated.

Let's see what for in loop does taking by example:

for fruit in fruits{

*Fruits = Array of String with fruit names

This loops means: "For each FRUIT NAME (STRING) stored in the FRUITS (ARRAY->STRING), do the code inside the brackets.". Thus, the loop is processing the code inside the brackets for each object inside your array, and you can manipulate the current object like we did printing it.

Is there ok now? Hope it helps you understanding it.

Ben Masel
Ben Masel
2,004 Points