Forums Register Login

A simple syntax question, pls help

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1054 times.
Similar Threads
dx = -dx; dy = -dy
C++ish Address &
exception java.lang.InterruptedException is never thrown in body of corresponding try statement
Help needed with the Code
New to Java. Need some proformance suggestions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:58:15.