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 trialVedang Patel
7,114 PointsWhere did the : come?
In for (char letter : mAnswer.toCharArray()) where did the : come from? This is really confusing I'm breaking my head on this one but its really hard to understand
1 Answer
Shane Robinson
7,324 PointsThat is an enhanced for loop, the :
is just part of the syntax (you would normally say it out loud as in
). So for your example, you would say it out loud as for each letter in answer
.
See this SO answer to see the enhanced next to a normal for loop, they both do the same thing here: http://stackoverflow.com/a/11685345
Vedang Patel
7,114 PointsVedang Patel
7,114 Pointsthanks