# if式@(例) a = 100 if a > 0 then if a > 10 then a += 1 end a += 1 end print( a ) # if式A(例) x=10 if x % 2 != 0 then print( x , "は奇数です" ) else print( x , "は偶数です" ) end # if式B(例) score = 75 grade = if score >= 70 then if score >= 80 then "A" else "B" end else if score >= 60 then "C" else "D" end end print( "Your score #{score} corresponds to #{grade}\n" ) # if式B(例) a = 100 if a > 10 then if a > 100 then a += 1 else a -= 1 end else if a > -10 then a += 10 else a -= 10 end end # if式C(例) if x >= 10 then print( x , "は10以上" ) elsif x >= 5 then print( x , "は5以上,10未満" ) elsif x >= 0 then print( x , "は0以上,5未満" ) else print( x , "は0未満" ) end # 無限の繰り返しA loop{ print( "こんにちは\n" ) } # 無限の繰り返しB i = 0 loop{ i = i+1 print( i , "回目のこんにちは\n" ) break if i == 10 } # 無限の繰り返しC i = 0 loop{ print( 10 ** i , "\n" ) break if i == 10 i = i+1 } # 無限の繰り返しD i = 1 loop{ if i % 2 == 0 then print( i , "\n" ) end break if i == 100 i = i+1 } # 無限の繰り返しD i = 2 loop{ print( i , "\n" ) break if i == 100 i = i+2 } # 無限の繰り返しE i = 1 total = 0 loop{ total += i break if i == 100 i = i+1 } print( "合計は" , total ) # キーボードからの入力(復習) loop{ line = gets.chomp break if line == "" print( line , "\n" ) } # 繰り返し入力できるようにするためには loop { print( "Enter your score: " ) line = gets.chomp break if line=="" score = line.to_f grade = if score >= 70 then if score >= 80 then "A" else "B" end else if score >= 60 then "C" else "D" end end print( "Your score #{score} corresponds to #{grade}\n" ) }