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 Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A simple syntax question, pls help

 
Jon Lee
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 ]
 
Barry Gaunt
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 ]
 
Megs Maquito
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.
 
Layne Lund
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic