Hi, When I use an Iterator of Object I use a while loop (as written in every book learning Java, as Thinking in Java of Bruce Eckel):
Iterator it=...
while(it.hasNext()){
//...
}
but sometime i saw than instead somebody use the for loop:
Iterator it=...
for (Iterator it=...; it.hasNext();;){
//...
}
I dont' understand this choice:
- I use the for loop when I have a collection with ordinal sequence (as array) or with a special rule for the step (declared generally as a simple increment
counter++
). - I use the while loop when the loop finish with I have'nt this constraints but only a logic condition for exit.
It's a question of style-coding without other cause or it exists some other logic (perfomance, for example) that I dont' know?
Thanks for every feedback