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 trialEugene Paitoo
3,922 PointsA little explanation
Please I need a little explanation on this code written at the Example.java class: for (Treet exampleTreet : treets) { System.out.println(exampleTreet); }
1 Answer
Mark Casavantes
Courses Plus Student 13,401 PointsGood Morning Eugene,
Basically, there is more than one way to create a for loop. What is listed below is what you may be most familiar with.
for (initialization condition; testing condition; increment/decrement)
{
statement(s)
}
There is also this way of creating a for loop which relates to the example you provided.
int [] numbers = {10, 20, 30, 40, 50};
for(int x : numbers )
{
System.out.print( x );
System.out.print(", ");
}
Mark
Ethan Goodwin
6,537 PointsEthan Goodwin
6,537 PointsTry watching the arrays series of videos for java.