When you need the loop to go on and on until the conditional is false, it’s convenient to use a while loop. When you have a predefined range that works as the conditional in a program you need to use for loops, finally when you need to call a function inside the same function it’s called a recursion, it makes it simpler but not always works as efficiently, each of these have different purposes, it’s a matter of knowing which suits the logic of the program best.
Here’s an example of each:
When to use what type of repetition in a program by tywins is licensed under a Creative Commons Attribution 4.0 International License.