Hi Yuji,
it seems to me you posted to the wrong forum (html, css, javascript), as your question seems
Java related, but anyway.
Each loop can serve all purposes, but each has some special area where it is most helpful in.
For loop - it automatically has a counter variable like "int i", so it is good if you need the index for something later one.
while loop - it is good if you don't care about the index, or if you don't continously step over each element, but have some special condition to be checked.
do while - rarely needed, and harder to understand, would be used in similar situations like the while loop, just that the first time the condition is not checked.
I would try to replace it by the regular while loop.
And in case yo are talking of Java > version 5, you would also have the
for each loop, (Element element: elements) {} which is very cool to iterate over collections.
Under the hood, it will use the iterator returned from your collection, so it should be very performant.
Actually, I have two videos made comparing the different loops. Check out episode 8 + 9 of my
Free Java Video Course.
Hope that helps.
Marcus