The Source for Java Technology Collaboration
User: Password:



Start New Message Post a Reply

Subject:  It should have been frozen at 1.4.
Date:  2008-01-15 09:26:38
From:  behrangsa
Response to: It should have been frozen at 1.4.


For a considerable number of cases the enhanced for loop is useless:

when you need the index of the element. I prefer

for (int i = 0; i < coll.size(); i++) {
// do somehing with i
// do something with coll.get(i);
}

rather than

int index = 0;
for (Clazz elem : coll) {
// do something with index
// do something with elem
}

In the first approach, the scope of i is just the for block, while in the second case, i is also accessible in the parent block. If we could somehow get a counter variable in the enhanced for loop maybe I would have changed my mind.

 Feed java.net RSS Feeds