if else switch case default n for while

  • Slides: 18
Download presentation

制御構造 条件分岐 if else switch case default n ループ処理 for while do break continue

制御構造 条件分岐 if else switch case default n ループ処理 for while do break continue n

復習) 論理演算 論理和 – || n n n いずれかが true ならば true || true

復習) 論理演算 論理和 – || n n n いずれかが true ならば true || true -- true || false – true false || true – true false || false – false ( 10 > 100 || 10 < 100 )

復習) 論理演算 論理積 -- && n n n いずれの値も true の時のみ true && true

復習) 論理演算 論理積 -- && n n n いずれの値も true の時のみ true && true – true && false – false && true – false && false – false ( 10 > 100 && 10 < 100 )

3つ以上の処理から選択 if( x > 100 ) { System. out. println( “Too big” ); }

3つ以上の処理から選択 if( x > 100 ) { System. out. println( “Too big” ); } else if( 0 <= x ) { System. out. println( “OK” ); } else { System. out. println( “Too small” ); }

switch – case による判定 int x ; switch( x ) { case 1: word

switch – case による判定 int x ; switch( x ) { case 1: word = “One”; break; case 2: word = “Two”; break; default: word = “”; }

繰り返し – whileのループ(2) int count = 1; while( count <= 10 ) { System.

繰り返し – whileのループ(2) int count = 1; while( count <= 10 ) { System. out. println( count ); count ++; } // count の値を 1 から 10 まで 10回表示

二重ループ for( int i=1; i<=9; i++ ) { for( int j=1; j<=9; j++) {

二重ループ for( int i=1; i<=9; i++ ) { for( int j=1; j<=9; j++) { System. out. println( i+j ); } } *9 X 9で81回の処理!