Consider a scenario where you are developing a menu-driven application. The user is presented with different options, and based on the user's selection, a specific action is performed. Which control structure would be the most appropriate to handle this?

  • Do-while loop
  • For loop
  • Switch statement
  • While loop
In this scenario, a switch statement would be the most appropriate control structure. It allows you to efficiently handle multiple options and execute specific code blocks based on the user's selection. Each case represents a different option, making the code more readable and maintainable compared to a series of if-else statements. The for, while, and do-while loops are used for iterative operations, not menu-driven options.
Add your answer
Loading...

Leave a comment

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