slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
讓程式轉彎 PowerPoint Presentation
Download Presentation
讓程式轉彎

Loading in 2 Seconds...

play fullscreen
1 / 16

讓程式轉彎 - PowerPoint PPT Presentation


  • 48 Views
  • Uploaded on

判斷. 讓程式轉彎. Loop. 迴圈. 迴圈的種類. while 迴圈 do while 迴圈 for 迴圈. for 迴圈 (1/3). for 迴圈的格式及執行流程:. for 迴圈敘述格式. for ( 設定迴圈初值 ; 判斷條件 ; 設定增減量 ) { 迴圈主體 ; }. 這兒不可以加分號. 這兒不可以加分號. 『 迴圈 』 敘述. 計數迴圈( for 迴圈敘述) for 迴圈語法. for( 初值設定運算式 ; 測試比較運算式 ; 增量設定運算式 ) { … 敘述區塊 … }. for 迴圈流程圖:.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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
slide1

判斷

讓程式轉彎

slide2

Loop

迴圈

slide3
迴圈的種類
  • while 迴圈
  • do while 迴圈
  • for 迴圈
for 1 3
for迴圈 (1/3)
  • for迴圈的格式及執行流程:

for迴圈敘述格式

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

{

迴圈主體;

}

這兒不可以加分號

這兒不可以加分號

slide5
『迴圈』敘述
  • 計數迴圈(for迴圈敘述)
    • for迴圈語法

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

{ … 敘述區塊 … }

for迴圈流程圖:

for迴圈執行流程:

slide6
求1~5的總和
  • 您會如何做???
    • 徒法鍊鋼法

public class stupid {

public static void main(String[] args){

int sum=0;

sum=1+2;

sum = sum +3;

sum = sum +4;

sum = sum +5;

}

}

slide7
求1~5(續)
  • 聰明法
for 3 3
for迴圈 (3/3)

下面的程式利用for迴圈計算1+3+...+30:

int sum=0;//why write here

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

sum += i;

}

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

while 1 3
while 迴圈 (1/3)

while迴圈敘述格式

設定迴圈初值;

while(判斷條件)

{

迴圈主體;

設定增減量;

}

這兒不可以加分號

這兒不可以加分號

while 2 3
While(2/3)

利用while 迴圈計算1+2+…+10:

while 3 3
While(3/3)

利用while迴圈計算1+3+...+30:

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

do while迴圈敘述格式

設定迴圈初值;

do

{

迴圈主體;

設定增減量;

} while(判斷條件);

要加分號

do while 2 2
do while 迴圈 (2/2)

下面的程式利用do-while迴圈計算1+2+...+10:

do{

sum +=i;

i++;

}while(i<=10);

nested loops 1 2
巢狀迴圈 (nested loops)(1/2)
  • 迴圈敘述中又有其它迴圈敘述時,稱為巢狀迴圈
  • 以列印部份的九九乘法表為例,練習巢狀迴圈:

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

{

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

敘述主體;

}

}