1、if和switch的使用場景比較html
1.分支比較多且沒法窮盡的時候,最好使用if,其餘狀況能夠視狀況而定git
2.若是數據不是很大,而且數據都是固定的能夠使用switchgithub
3.理論上Switch的效率更高微信
4.switch的弊端在於若是是無窮的可能性,那麼就不適合使用switch學習
2、循環大數據
1.while循環,格式同Java;break,continue使用方法同Java。ui
2.do.....while語句格式spa
do{
語句;
}while(條件);
3.for循環同Java用法一致.net
4.舉個例子code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>D12_1_Circulation</title> <style> span{ display:inline-block; border:1px solid black; margin:5px; padding:10px; } </style> </head> <body> <script> //案例:判斷用戶輸入的數字是否是大於100 var score; score = +(window.prompt("請輸入一個0到100的分數\n")); if(score > 100){ parseInt(score); } //實現一個99乘法表 for(var i=1;i<=9;i++){ for(var j=1;j<=i;j++){ document.write("<span>"+j+"*"+i+"="+i*j+"</span>") } document.write("<br/>") } </script> </body> </html>
3、源碼:
D12_1_Circulation.html
地址:
https://github.com/ruigege66/JavaScript/blob/master/D12_1_Circulation.html
2.CSDN:https://blog.csdn.net/weixin_44630050
3.博客園:https://www.cnblogs.com/ruigege0000/
4.歡迎關注微信公衆號:傅里葉變換,我的帳號,僅用於技術交流,後臺回覆「禮包」獲取Java大數據學習視頻禮包