• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what does this code mean?

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic