Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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