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 Loop

Matthew Lurie
Matthew Lurie
3,512 Points

How should you decide upon a name for the "task" in "for task in todo"?

I tested out "for bananas in todo { print(bananas) }" and that worked as well. What's the thinking behind picking an appropriate name for that string?

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! In Swift (and really many other languages) the first part of a for ... in type loop is a variable name. Here are some other appropriate examples:

  • for fish in fishbowl
  • for fruit in fruitBasket
  • for book in bookShelf

The first word of all of these will be the variable name for the individual item we're looking at right then. He could have also used for action in todo, for item in todo, or any other name that makes sense in terms of the individual in relation to the group as a whole.

Hope this helps! :sparkles: