MTEL Digital Literacy and Computer Science

Category - Digital Lit and CS

In which of the following situations is it more appropriate to use a while loop than a for loop?
  1. The number of times a loop will execute is not known in advance.
  2. The loop is called from within a procedure.
  3. The number of statements in the loop body is greater than 10.
  4. The loop continues until a condition is satisfied.
Explanation
Correct Response: A. While either type of loop could technically be used in this case, a for loop is generally associated with numeric counters, while a while loop continues to execute until a statement evaluates to a predetermined Boolean value. B is incorrect because either type of loop could be called from within a function or procedure. C is incorrect, as the number of statements does not limit either kind of loop. D is incorrect because both types of loop continue until a condition is satisfied.
Was this helpful? Upvote!
Login to contribute your own answer or details

Top questions

Related questions

Most popular on PracticeQuiz