• Post Reply Bookmark Topic Watch Topic
  • New Topic

when should I use the for-each loop?  RSS feed

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when should Iuse the for-each loop in my code???

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you want to iterate through a sequence, such as an array or anything that implements Iterable (like various collections).
[ August 25, 2004: Message edited by: Dirk Schreckmann ]
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you...
 
Matt Rasking
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good description of loops in J2SE 1.5, including a comparison of "while" and "for" with the new "for each" looping construct.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!