When it comes to choosing a loop, it all depends on the situation. So, the best way to know what kind of loop is needed takes practice.
- If you know the number of iterations you need to make, a for loop may be a good choice. Otherwise, a while loop may be better.
- If you want to go through all properties of an object, use a for in loop.
- If you want to go through everything in an iterable, use a for of loop.
- If you want to run some piece of code once and you don't know the number of times the loop should be repeated, use a do while loop.