What Kind of Loop to Use
-
The for-loop is suitable for a loop that involves numerical calculation using a variable that is changed by equal amounts each time through the loop.
-
In most other cases, you should consider using a
while or a do-while-loop.
-
Use a while-loop if there is a chance that the loop may not execute even once.
-
Use a do-while-loop if the loop must execute at least once.