Alex wants to create a menu-driven program that keeps displaying the menu until the user selects the 'Exit' option. Which loop is best suited for this task?

  • do-while loop
  • for loop
  • switch loop
  • while loop
Alex should use a do-while loop for this purpose. A do-while loop executes a block of code at least once and then repeats it based on a condition. It's ideal for menu-driven programs because it ensures that the menu is displayed at least once, even if the user chooses to exit immediately.
Add your answer
Loading...

Leave a comment

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