Skip to content

Instantly share code, notes, and snippets.

@tigawa
Last active December 11, 2015 18:59
Show Gist options
  • Save tigawa/4645886 to your computer and use it in GitHub Desktop.
Save tigawa/4645886 to your computer and use it in GitHub Desktop.
ruby 制御構造(if while …)
#if
if count > 10
puts "もう一度挑戦してください。"
elsif tries == 3
puts "あなたの負けです。"
else
puts "数字を入力してください。"
end
#while
while weight < 100 and num_pallets <=30
pallet = next_pallet()
weight += pallet.weight
num_pallets +=1
end
#unless 条件を満たしていない時に実行する
#until 条件を満たすまで繰り返し実行する
#文修飾子 本体が1つだけの式の場合に、利用できる。
puts "きけんです” if radiation > 3000
distance = distance * 1.2 while distance < 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment