• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing iterator in enhanced for construct

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the enhanced for, can you access the relative index being iterated.

 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, for that you need to use the old-style for loop. They considered some ways that the for loop might have been made more powerful - access to the index, or to the iterator's remove() method, etc - but instead decided to keep the syntax as simple as possible, as that covers, what, 80% or more of the cases where you use a for loop? And the remaining more complex cases can always be handled by the original for loop syntax.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification.
In my case, the new style is great 99.44% of the time
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic