• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what does this code mean?

 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for(Animal animal : a) {
animal.makeNoise();
if(animal instanceof Dog) {
animal.playDead();
}
}


AND

for(CoffeeSize cs: CoffeeSize.values())
System.out.println(cs + " " + cs.getOunces());

How does this kind of for loop work?(having just a colon)
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4330
238
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gari,
Welcome to JavaRanch

That is a for-each loop. It's a kind of for-loop which iterates through a given array or a collection. Have a look at this article.
Also, please don't forget to UseCodeTags when you post a source code on the forum.

Devaka
 
Gari Jain
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devaka Cooray wrote:Hi Gari,
Welcome to JavaRanch

That is a for-each loop. It's a kind of for-loop which iterates through a given array or a collection. Have a look at this article.
Also, please don't forget to UseCodeTags when you post a source code on the forum.

Devaka


Thankyou
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic