Peter is developing a program where he wants to repeatedly ask the user for input until the user provides a valid response. Which loop should Peter use?

  • do-while loop
  • for loop
  • switch loop
  • while loop
Peter should use a while loop in this scenario. A while loop repeatedly executes a block of code as long as a given condition is true. It's suitable for situations where the program needs to keep asking for input until a certain condition is met, such as validating user input.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *