What Kind of Loop to Use

  1. 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.

  2. In most other cases, you should consider using a while or a do-while-loop.

  3. Use a while-loop if there is a chance that the loop may not execute even once.

  4. Use a do-while-loop if the loop must execute at least once.