what is switch case code example
Example 1: switch case c
switch (expression) {
case constant1:
break;
case constant2:
break;
default:
}
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"))
console.log(whatToDrink("evening"))
console.log(whatToDrink("night"))
console.log(whatToDrink("daytime"))
Example 3: switch statement
int x = Random.Range(0, 5);
switch(x){
case 0:
break;
case 1:
break;
}
Example 4: switch case c
switch(expression) {
case constant-expression :
statement(s);
break;
case constant-expression :
statement(s);
break;
default :
statement(s);
}