I often see code like:
Iterator i = list.iterator(); while(i.hasNext()) { ... }
but I write that (when Java 1.5 isn't available or for each can't be used) as:
for(Iterator i = list.iterator(); i.hasNext(); ) { ... }
because
i
I think code should be as simple to understand as possible so that I only have to make complex code to do complex things. What do you think? Which is better?
From: http://jamesjava.blogspot.com/2006/04/iterating.html
I prefer the for loop because it also sets the scope of the iterator to just the for loop.
2.1m questions
2.1m answers
60 comments
56.9k users