Download Presentation

Loading in 2 Seconds...

1 / 16

# 讓程式轉彎 - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

## PowerPoint Slideshow about '讓程式轉彎' - brielle-brock

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Loop

• while 迴圈
• do while 迴圈
• for 迴圈
for迴圈 (1/3)
• for迴圈的格式及執行流程：

for迴圈敘述格式

for(設定迴圈初值; 判斷條件; 設定增減量)

{

}

『迴圈』敘述
• 計數迴圈（for迴圈敘述）
• for迴圈語法

for(初值設定運算式;測試比較運算式;增量設定運算式)

{ … 敘述區塊 … }

for迴圈流程圖：

for迴圈執行流程：

• 您會如何做???
• 徒法鍊鋼法

public class stupid {

public static void main(String[] args){

int sum=0;

sum=1+2;

sum = sum +3;

sum = sum +4;

sum = sum +5;

}

}

• 聰明法
for迴圈 (3/3)

int sum=0;//why write here

for(inti=1;i<=30;i +=2 ){

sum += i;

}

System.out.println("sum="+sum);

while 迴圈 (1/3)

while迴圈敘述格式

while(判斷條件)

{

}

While(2/3)

While(3/3)

do while 迴圈 (1/2)
• do while是用於迴圈執行的次數未知時
• do while至少會執行1次迴圈主體

do while迴圈敘述格式

do

{

} while(判斷條件);

do while 迴圈 (2/2)

do{

sum +=i;

i++;

}while(i<=10);

• 迴圈敘述中又有其它迴圈敘述時，稱為巢狀迴圈
• 以列印部份的九九乘法表為例，練習巢狀迴圈：

for(設定迴圈初值; 判斷條件; 設定增減量)

{

for(設定迴圈初值; 判斷條件; 設定增減量){

}

}