Looping is a valuable part of programming. Generally speaking, a for loop is used when:
You know the start value.
You know the end value.
You can get from start to end value by counting.
This is called a counted loop. You can count up or down or use any of the mathematical operators to manipulate the variable being used as a counter. You initialize the counter to the start value and then check it against an end value, which can be constant or derived.
A while loop is useful when you are testing for a given condition to arise where the number of iterations may vary, depending on the code executed within the loop itself. Thus, it is useful when you do not know how you will get from the start to the end value and need to do some complex processing ...