Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about MalaGupta's Review Note 5.9 (Enhanced for)

 
Winston Liek
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Accdg to the book:

[javadoc]The enhanced for loop can’t be used to iterate over multiple collections or
arrays in the same loop.[/javadoc]

It does not provide any explanation/examples there..

Can someone please provide an example or explanation please enlighten me.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take these arrays as an example:


With a regular for loop you could write something like the following code snippet to print both arrays. This is not possible using the enhanced for loop. And of course the same applies if I had used collections instead of arrays:


Hope it helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic