What is difference between for loop and while loop in Java?
Java for Loop vs while Loop vs do-while Loop
The Java for loop is a control flow statement that iterates a part of the programs multiple times. The Java while loop is a control flow statement that executes a part of the programs repeatedly on the basis of given boolean condition.
When should you use a while loop over a for loop?
In general, you should use a for loop when you know how many times the loop should run. If you want the loop to break based on a condition other than the number of times it runs, you should use a while loop.