cwicth c code example

Example 1: 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

Example 2: c switch case

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

    case constant2:
      // statements
      break;

    default:
      // default statements
}

Tags:

Misc Example