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

Android Build a Self-Destructing Message Android App Relating Users in Parse.com Executing a Query

What does ParseUser user : mUsers means?

What does ParseUser user : mUsers means? Why is the for loop different than previous? Please explain

1 Answer

This is a foreach loop. Basically it loops one time for each "user" variable of type ParseUser that is contained in the variable mUsers. Let's say mUsers contains 3 users of type ParseUser. It gets the first one and assigns it to "user" then enters the loop and does everything inside for that current user. It then picks the next one, assigns it to "user again" and so on, untill it does it for the last such element.

why can't we use for(int i = 0; i<mUser.size(): i++) to determine the loop needed?

In different situation, one may be faster and better to use than the other. As to which one you should use, this is greatly expalined here - http://www.dotnetperls.com/for-foreach

And a bit more clarity - http://stackoverflow.com/questions/365615/in-net-which-loop-runs-faster-for-or-foreach