This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • 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: 4259
227
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