-5

I have a list of objects called employee() and I used emp as my object. I want to increment over employees and print the name of all the objects. I really lost on how to do this. Thanks.

for( emp ;  ;employees())
        {
        System.out.println(emp.name);
        }
AwayFromMyDesk
  • 109
  • 1
  • 9
  • [Don't come back until you've read this](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html) – Sotirios Delimanolis Oct 16 '13 at 03:41
  • Yeah, it is. I didn't know the name of the "for each" loop. The reason I can see for keeping it is that for for other people that don't know what "for each" loop is, they might be able to find their answer through this thread. – AwayFromMyDesk Oct 16 '13 at 03:50
  • @SotiriosDelimanolis, I did read that. It wasn't too helpful for iterating over objects from a newb's point of view. I was mixing things up as Woody righted me. – AwayFromMyDesk Oct 16 '13 at 04:00
  • @AwayFromMyDesk You aren't serious... The last three paragraphs of the link is exactly about that, with examples and everything. All I had to do was type `java for loop` into google. – Sotirios Delimanolis Oct 16 '13 at 04:01
  • @SotiriosDelimanolis, when the example uses int's it's more clear from somebodies point of view that has never touched OOP before. Using my own objects made it a little more foggy. Obviously, I set up the for loop (which I also did after typing it into Google) but was putting the parameters in incorrectly. – AwayFromMyDesk Oct 16 '13 at 04:06
  • I don't know what else I can say. `java for loop objects` in Google brings up all sorts of results. – Sotirios Delimanolis Oct 16 '13 at 04:08

1 Answers1

1

Try using foreach()

for(Employee employee : employees())
{
System.out.println(employee.name);
}
Woody
  • 930
  • 9
  • 23