diff --git a/for.rb b/for.rb new file mode 100644 index 0000000..340384c --- /dev/null +++ b/for.rb @@ -0,0 +1,14 @@ +# 1から5までの合計を求める +sum = 0 +for i in 1..5 + sum = sum + i +end +print sum, "\n" +# fromからtoまでの合計を求める +from = 10 +to = 10 +sum = 0 +for i in from..to + sum = sum + i +end +print sum, "\n" diff --git a/times.rb b/times.rb new file mode 100644 index 0000000..739b299 --- /dev/null +++ b/times.rb @@ -0,0 +1,9 @@ +# encoding: UTF-8 + +4.times do + print "いちめんのはな\n" +end + +5.times { + print "いちめんの花\n" +} diff --git a/times2.rb b/times2.rb new file mode 100644 index 0000000..b19aa1d --- /dev/null +++ b/times2.rb @@ -0,0 +1,5 @@ +#encoding: UTF-8 + +5.times do |i| + print i,"回目の繰り返しです。\n" +end diff --git a/times3.rb b/times3.rb new file mode 100644 index 0000000..3a0cfef --- /dev/null +++ b/times3.rb @@ -0,0 +1,5 @@ +#encoding: UTF-8 + +5.times do |i| + print i+1, "回目の繰り返しです。\n" +end