They are pretty much same except for do-while
loop. The for
loop is good when you have a counter
kind of variable. It makes it obvious. while
loop makes sense in cases where a flag is being checked as show below :
while (!done) {
if (some condtion)
done = true;
}