switch in c with same case code example

Example 1: switch case c

switch (expression) {
    case constant1:
      // statements
      break;

    case constant2:
      // statements
      break;

    default:
      // default statements
}

Example 2: switch case in

function whatToDrink(time){
    var drink ;
          switch (time) {
            case "morning":
              drink = "Tea";
              break;
            case "evening":
              drink = "Shake";
              break;
            default:
              drink="Water";   
          }
  	return drink;
}
console.log(whatToDrink("morning")) //Tea
console.log(whatToDrink("evening")) //Shake
console.log(whatToDrink("night"))   //Water
console.log(whatToDrink("daytime")) //Water

Tags:

C Example