環境
ruby 2.4.1p111
ループ処理(for in do end)
sample.rb
for i in 0..10 do
puts "ループ変数=#{i}"
end
#(出力結果)
ループ変数=0
ループ変数=1
ループ変数=2
ループ変数=3
ループ変数=4
ループ変数=5
ループ変数=6
ループ変数=7
ループ変数=8
ループ変数=9
ループ変数=10
配列ループ処理
sample.rb
employees = ["Yamada", "Tanaka", "Satoh"]
for emp in employees do
print(emp + "¥n")
end
#(出力結果)
Yamada
Tanaka
Satoh
ループ処理(while do end)
sample.rb
i = 0
while i <= 10 do
puts "ループ変数=#{i}"
i+=1
end
#(出力結果)
ループ変数=0
ループ変数=1
ループ変数=2
ループ変数=3
ループ変数=4
ループ変数=5
ループ変数=6
ループ変数=7
ループ変数=8
ループ変数=9
ループ変数=10