PHP 04 循環結構
◆什麼時候須要循環結構?
• 循環輸出一百次你好;學習
• 將字符輸出指定次數;spa
◆while 循環
![](http://static.javashuo.com/static/loading.gif)
◆使用while 循環-1
• 打印50「次好好學習,每天向上」for循環
• 使用while循環的步驟循環
- • 肯定循環次數
- • 聲明計數器
- • 套用while循環格式
- • 實現循環代碼塊
◆使用while 循環-2
![](http://static.javashuo.com/static/loading.gif)
◆示例:
• 對100之內的偶數求合im
• 提示:總結
- • 從1到100循環一百次的while循環
- • 在while循環內加入if選擇結構
- • 將選擇出來的偶數累加起來獲得結果
◆break 和 continue
- break;語句用來終止循環
- continue;語句用來跳過本次循環
◆使用break;語句
![](http://static.javashuo.com/static/loading.gif)
◆使用continue;語句
![](http://static.javashuo.com/static/loading.gif)
◆do-while循環
![](http://static.javashuo.com/static/loading.gif)
◆for循環
![](http://static.javashuo.com/static/loading.gif)
◆for循環運行順序
![](http://static.javashuo.com/static/loading.gif)
◆使用for循環
![](http://static.javashuo.com/static/loading.gif)
◆常見問題
![](http://static.javashuo.com/static/loading.gif)
◆循環的嵌套
![](http://static.javashuo.com/static/loading.gif)
◆嵌套常見問題
• 內層循環使用外層循環計數器img
• 在內層循環改變外層循環計數器的值思考
• 大括號問題while
• 注意:出現大括號不對應問題刪了重寫!co
◆思考
實現打印九九乘法表
提示:外循環控制行數
內循環控制列數
![](http://static.javashuo.com/static/loading.gif)
◆概要總結
• 循環結構的概念和做用
• while和do-while語句的運用
• for循環的運用
• break和continue流程控制
• 嵌套循環的運用
歡迎關注本站公眾號,獲取更多信息