• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

A simple syntax question, pls help

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code is taken from "Core Java 7ED". There is one line of code I can not understand. That line No. is 90. What does it mean??? I never read a "for" loop code like this. Pls give some hints, Thnx a lot!



[ August 13, 2005: Message edited by: Jon Lee ]
[ August 13, 2005: Message edited by: Jon Lee ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the new for loop construct that appeared in Java 5.0. You can read it as "for each Ball b in the collection (or array) balls, perform the following (whatever is in the {})". It is known as the "foreach" construct.
You can use break or continue as you would in a normal loop.
[ August 13, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the enhanced for loop as said. It means go through every element of balls ArrayList as you go through the list one at a time starting from [0]and put the value in b each time you do so.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you reading Volume 1-Fundamentals or Volume 2-Advanced Topics? Volume 1 will explain this and other new features that come with Java 5.0, so it might be worth your time buying the new edition of Volume 1 even if you already own an older edition.

Layne
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see. I dont read volume one yet. Maybe I should go through volume one qucikly to see the new features in Java 5.0.

Thnx for your replies, guys.

[Please do not offer to share copyrighted materials through JavaRanch. In fact, don't offer to share them at all. The people who produce such things deserve to be paid properly for their work -- mfe]

Cheers
[ August 16, 2005: Message edited by: Michael Ernest ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a very generous offer, but if the authors or publishers see it, you may be heading for some trouble since they own the copyrights and probably frown on people giving it away without their permission. In fact, the authors were here at the Ranch fairly recently for a book promotion...

Layne
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Layne Lund:
That's a very generous offer, but if the authors or publishers see it, you may be heading for some trouble since they own the copyrights and probably frown on people giving it away without their permission. In fact, the authors were here at the Ranch fairly recently for a book promotion...

Layne



Thank you for mentioning that Layne. Jon please take notice.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, thnx for your reminder. I will not share the books any more. BTW, the CORE Java series are great books for beginners. It is worth your money.
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!