aspose file tools*
The moose likes Beginning Java and the fly likes what does this code mean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what does this code mean?" Watch "what does this code mean?" New topic
Author

what does this code mean?

Gari Jain
Ranch Hand

Joined: Jun 29, 2009
Posts: 100
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)

OCPJP 6-100%; Preparing for GATE11
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3220
    
  49

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


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Gari Jain
Ranch Hand

Joined: Jun 29, 2009
Posts: 100
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what does this code mean?