1.while函數
2.do...whileui
3.while和do...while有什麼區別?spa
1.while語法格式code
while(表達式) { //表達式爲真則執行代碼塊 //代碼塊 }
2.執行流程圖視頻
3.舉個例子blog
var count = 1; //新建變量count, 賦值爲1 while (count<100) { //表達式,當count的值小於100的時候,執行代碼塊 document.write(count); //打印出count的值,當值爲99的時候,中止打印 count++; //值每次遞增1 }
1.do...while語法格式教程
do{ //總會執行一次 //代碼塊 }while (表達式);
2.執行流程圖rem
3.舉個例子get
var count = 1; do{ document.write(count); //不作判斷,先執行這個代碼塊 count++; }while(count<100); //判斷表達式,爲真,重複這個循環
while循環語句:先判斷表達式是否爲true, 若是爲true,則執行循環體,不然不執行,屬於先判斷再執行。
do while語句:先執行do代碼塊,而後再對while表達式作判斷,do代碼塊總會被執行一次,屬於先執行再判斷。