Switch Statement के द्वारा multiple case के condition को check कराया जाता है, जिस case का condition true होता है उस case को run करता है, यदि कोई case true नहीं होता है तो default case होता है
हर statement के बाद break लगाना पड़ता है, इसका मतलब वो उसके पहले का Cae Run करेगा | अगर break नहीं लगाया जाता तो वो पहला और दूसरा ये दोनों statement को execute करेगा | default case के बाद break नहीं लगाते |
switch(expression){
case 1 :
statement(s);
break;
case 2 :
statement(s);
break;
case n…
statement(s);
break;
default :
statement(s);
}
<script>
var day =3;
switch(day){
case 0 :
document.write("Today is Sunday.");
break;
case 1 :
document.write("Today is Monday.");
break;
case 2 :
document.write("Today is Tuesday.");
break;
case 3 :
document.write("Today is Wednesday.");
break;
case 4 :
document.write("Today is Thurday.");
break;
case 5 :
document.write("Today is Friday.");
break;
case 6 :
document.write("Today is Saturday.");
break;
default :
document.write("Day is Not Found.");
}
</script>
<script>
var day =3;
switch(day){
case 0 :
document.write("Today is Sunday.");
break;
case 1 :
document.write("Today is Monday.");
break;
case 2 :
document.write("Today is Tuesday.");
break;
case 3 :
document.write("Today is Wednesday.");
break;
case 4 :
document.write("Today is Thurday.");
break;
case 5 :
document.write("Today is Friday.");
break;
case 6 :
document.write("Today is Saturday.");
break;
default :
document.write("Day is Not Found.");
}
</script>