Answer:
- You know how many times you want the loop to run.
- When there is a defined start and end.
Explanation:
Required:
When to use for instead of while loop?
First, it should be noted that both for loop and while loop are used for iteration. However, depending on the scenario; there is preference on one to the other.
The basic syntax of for loop is:
<em>The condition could either be increment or decrement</em>
The basic syntax of while loop is:
<em>The condition could be any condition whatsoever</em>
Analyzing the options one after the other.
1. How many times the loop to run.
The for loop is preferred here because of the simplicity of the for loop.
2. & 3. Both the for and while loops are used for code repetition and to perform number calculations
4. Defined start and end.
From the syntax of the for loop
<em />
A for loop has a definite start and end in its basic syntax and is more preferable to use instead of a while loop.
<em />
<em />
Hence, 1 & 4 answer the question