211k views
3 votes
Which situations are better suited to an indefinite (while) loop? Select 3 options.

A. writing a program that will average 20 numbers
B. writing a program to average the temperatures for the last 30 days
C. having the user guess a number and keep guessing till they get it right
D. allowing the user to enter their best friends names without saying how many friends they can have
E. writing a program to average numbers without requiring the user to count the numbers

User Susilo
by
6.3k points

1 Answer

1 vote

Answer:

C. having the user guess a number and keep guessing till they get it right

D. allowing the user to enter their best friends names without saying how many friends they can have

E. writing a program to average numbers without requiring the user to count the numbers

Step-by-step explanation:

Indefinite (while) loops are useful when we don't know exactly how many iterations will be needed, or when the user should be able to keep performing an action until a certain condition is met. In the situations described in options B, C, and D, we don't know exactly how many times the loop will need to execute, so an indefinite loop would be appropriate. In option A, we know that we will need to average exactly 20 numbers, so a definite (for) loop with 20 iterations would be more appropriate.

User Justin Moser
by
7.1k points