Presentation is loading. Please wait.

Presentation is loading. Please wait.

4章 制御の流れ-3.

Similar presentations


Presentation on theme: "4章 制御の流れ-3."— Presentation transcript:

1 4章 制御の流れ-3

2 do-while 文 do { 文1; 文n; } while (条件式) no yes

3 continueとbreak(1) (while文の場合) continue文 継続条件式の評価へ分岐
while (継続条件式) { 文1; if (...) continue; 文n; } no yes continue (while文の場合) continue文 継続条件式の評価へ分岐

4 continueとbreak(2) continue文 for文の場合はカウンタ変数の更新へ分岐
for (初期化;継続条件;カウンタ変数の更新) { 文1; if (条件式) continue; 文n; } continue文  for文の場合はカウンタ変数の更新へ分岐

5 continueとbreak(3) while (条件式) { 文1; if (...) break; 文n; }
no yes break break文 くり返しから抜け出す

6 continueとbreak(4) if文と組み合わせて使用する for、while、do-whileで使える continue
一つのループの中に複数存在できる

7 無限ループ(1) 条件式が真の時の値は1 while (1) { 文; } for (;;)

8 無限ループ(2) for (;;) { 文1; if (i >= 10) break; } 文2;

9 goto文 ラベル : 文 ; goto ラベル; (1)多重のくり返し構造の内側からの脱出 (2)例外処理の記述
名札付き文 goto 文 (1)多重のくり返し構造の内側からの脱出 (2)例外処理の記述 などの他の方法が無い場合だけ使う

10 条件演算子 式1 ? 式2 : 式3 ; 式1が真ならば式2、 偽ならば式3を実行する。 (3項演算子)

11 2重ループ(1) /* 66666 Tachibana Masayoshi */ #include "stdafx.h"
int main(void) { int i,j,n; n = 1; for (i=0;i<5;i++) printf("%d: ",i); for (j=0;j<7;j++) printf("%5d ",n); n = n+1; } printf("\n"); return 0; 2重ループ(1)

12 2重ループ(2) 0: 1: 2: 3: 4:

13 2重ループ(3) #include "stdafx.h" int main(void) { int i,j,n; n = 1;
for (i=0;i<5;i++) printf("%d: ",i); for (j=0;j<7;j++) printf("%5d ",n); n = n+1; } printf("\n"); return 0; 二重になったfor文 内側のfor文が終了したら改行

14 2重ループ(4) 外側のfor文が出力 内側のfor文が出力 0: 1 2 3 4 5 6 7 1: 8 9 10 11 12 13 14
0: 1: 2: 3: 4: 内側のfor文が終了したら改行


Download ppt "4章 制御の流れ-3."

Similar presentations


Ads by Google