Ruby

【Ruby】times, uptoの小さなメモ

###########
# times
10.times{|i|
  p "times: #{i}"
}

10.times{
  p "times"
}


10.times do |i|
  p "times: #{i}"
end

10.times do
  p "times"
end


#########
# upto

10.upto(15){
  p "upto"
}

10.upto(15){ |i|
  p "upto: #{i}"
}


10.upto(15) do
  p "upto"
end


10.upto(15) do |i|
  p "upto: #{i}"
end
結果
"times: 0"
"times: 1"
"times: 2"
"times: 3"
"times: 4"
"times: 5"
"times: 6"
"times: 7"
"times: 8"
"times: 9"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times: 0"
"times: 1"
"times: 2"
"times: 3"
"times: 4"
"times: 5"
"times: 6"
"times: 7"
"times: 8"
"times: 9"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"times"
"upto"
"upto"
"upto"
"upto"
"upto"
"upto"
"upto: 10"
"upto: 11"
"upto: 12"
"upto: 13"
"upto: 14"
"upto: 15"
"upto"
"upto"
"upto"
"upto"
"upto"
"upto"
"upto: 10"
"upto: 11"
"upto: 12"
"upto: 13"
"upto: 14"
"upto: 15"

Process finished with exit code 0