Which language construct can best represent the following series of if conditionals?

if($a == 'a') {
  somefunction();
} else if ($a == 'b') {
  anotherfunction();
} else if ($a == 'c') {
  dosomething();
} else {
  donothing();
}

  1. A switch statement without a default case

  2. A recursive function call

  3. A switch statement using a default case

  4. A while statement


Correct Option: C
Explanation:

A series of if…else if code blocks checking for a single condition as above is a perfect place to use a switch statement

Find more quizzes: