Answer:
1. You do not know how many times a loop will need to run
4. To repeat code.
Explanation:
Required
When to use while loop instead of for loop?
Option 1 and 4 answer the question
<em>1. You do not know how many times a loop will need to run
</em>
Using while loop in this case is suitable to the for loop.
Take for instance
You want a set of instruction to be repeated until the user enters 1
e.g.
<em>while a != 1:</em>
<em> print("abc")</em>
<em> print("def")</em>
<em> a = int(input("Input: "))</em>
<em />
The above is written in Python
The print instructions will be repeated until the user enter 1.
Now, you do not know if the user will enter 1 the first time or the 100th time or the 10000th time.
In other words, you don't know how many times the loop will be executed.
In this case, while loop is preferred to for loop
4. To repeat code:
The same analysis as used in (1) above is applicable in (4).
The print statements in
<em>while a != 1:</em>
<em> print("abc")</em>
<em> print("def")</em>
<em> a = int(input("Input: "))</em>
will be repeated until the user enters 1
The for loop isn't preferable in this case
<em>Other options (2) and (3) can be implemented using both the for loops and the while loops</em>