switch example
Example 1: java switch
int day = 4;
switch (day) {
case 6:
System.out.println("Today is Saturday");
break;
case 7:
System.out.println("Today is Sunday");
break;
default:
System.out.println("Looking forward to the Weekend");
}
Example 2: switch function
var rand = Math.round(random(1,4));
switch(rand){
case 1: console.log("Chosen Number : 1");
break;
case 2: console.log("Chosen Number : 2");
break;
case 3: console.log("Chosen Number : 3");
break;
case 4: console.log("Chosen Number : 4");
default: break;
}
Example 3: 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 4: switch statement
int x = Random.Range(0, 5);
switch(x){
case 0:
break;
case 1:
break;
}