国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

switch/case statement

switch/case statement

When making a large number of selection judgments, if you still use the if/else structure, the code may become very complicated. It’s messy, so we use the switch/case structure:

switch(k)
{
case k1:
  執(zhí)行代碼塊 1 ;
  break;
case k2:
  執(zhí)行代碼塊 2 ;
  break;
default:
  默認(rèn)執(zhí)行(k 值沒(méi)有在 case 中找到匹配時(shí));
}

Syntax description:

Switch must be assigned an initial value, and the value matches each case value. Satisfies all statements after executing the case, and uses the break statement to prevent the next case from running. If all case values ??do not match, the statement after default is executed.

Assuming that students' test scores are evaluated on a 10-point full-score system, we grade the scores according to each grade and make different evaluations based on the grade of the scores.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>switch</title>
<script type="text/JavaScript">
var myweek =1;//myweek表示星期幾變量
switch(myweek)
{
 case 1:
 case 2:
 document.write("學(xué)習(xí)理念知識(shí)");
 break;
 case 3:
 case 4:
 document.write("到企業(yè)實(shí)踐");
 break;
 case 5:
 document.write("總結(jié)經(jīng)驗(yàn)");
 break;
 case 6:
 case 7:
 document.write("周六、日休息和娛樂(lè)");
 break;
 default:
 window.alert('輸入有誤');
}
</script>
</head>
<body>
</body>
</html>
rrree


Continuing Learning
||
<!DOCTYPE html> <html> <body> <p>點(diǎn)擊下面的按鈕來(lái)顯示今天是周幾:</p> <button onclick="myFunction()">點(diǎn)擊這里</button> <p id="demo"></p> <script> function myFunction() { var x; var d=new Date().getDay(); switch (d) { case 0: x="Today it's Sunday"; break; case 1: x="Today it's Monday"; break; case 2: x="Today it's Tuesday"; break; case 3: x="Today it's Wednesday"; break; case 4: x="Today it's Thursday"; break; case 5: x="Today it's Friday"; break; case 6: x="Today it's Saturday"; break; } document.getElementById("demo").innerHTML=x; } </script> </body> </html>
submitReset Code