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.
Loading...
Related Quiz
- Which C++ statement is used to make a single conditional decision?
- Which access specifier in C++ allows a class member to be accessible only within the class and friends of the class?
- How does C++ treat an enum regarding its type and size?
- When might using a table of function pointers be preferable over a switch-case statement for handling various cases/conditions?
- Which keyword is used in C++ to make a function virtual?