1 / 5

巢狀迴圈

巢狀迴圈. 如同 VB 一樣,在學會了單層迴圈後,接下來就要練習巢狀迴圈。 雖說 『 巢狀 』 ,其實大部份的程式也不過雙層而已,三層以上很少用到。. 例題. 設計一程式,輸入一整數,求小於等於該整數的所有質數。 要求:每 5 個質數之後要換一列。 畫面例: 200 以內的質數. 例題 : 九九乘法表. 要求:每 9 個數之後要換一列。 畫面例:表格. 九九乘法表 程式碼. <script language="javascript"> var i, j; for(i=1;i<=9;i++) { document.write("<tr>");

zlata
Download Presentation

巢狀迴圈

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 巢狀迴圈 如同 VB 一樣,在學會了單層迴圈後,接下來就要練習巢狀迴圈。 雖說『巢狀』,其實大部份的程式也不過雙層而已,三層以上很少用到。 巢狀迴圈

  2. 例題 • 設計一程式,輸入一整數,求小於等於該整數的所有質數。 • 要求:每 5 個質數之後要換一列。 • 畫面例:200 以內的質數 巢狀迴圈

  3. 巢狀迴圈

  4. 例題:九九乘法表 • 要求:每 9 個數之後要換一列。 • 畫面例:表格 巢狀迴圈

  5. 九九乘法表 程式碼 <script language="javascript"> var i, j; for(i=1;i<=9;i++){ document.write("<tr>"); for(j=1;j<=9;j++) { document.write("<td>"); document.write(i + "*"+ j + "="+ i * j); document.write("</td>"); } document.write("</tr>"); } </script> 巢狀迴圈

More Related