Which of the following do you use for a multi-way branch?

  1. If

  2. Ifthen

  3. Ifelse

  4. switch

  5. for


Correct Option: D
Explanation:

To solve this question, the user needs to know the different programming constructs used for branching and looping.

Option A: if statement is used for a two-way branch, where the code executes only if the condition is true. It is not used for a multi-way branch.

Option B: ifthen is not a valid programming construct.

Option C: ifelse is used for a two-way branch, where the code executes one block if the condition is true and another block if the condition is false. It is not used for a multi-way branch.

Option D: switch statement is used for a multi-way branch, where the code executes different blocks of code based on different possible values of an expression.

Option E: for loop is used for repeating a block of code for a specific number of times or for iterating over a collection of items. It is not used for branching.

Therefore, the correct answer is:

The Answer is: D. switch

Find more quizzes: