「Ruby/for」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→foreach) |
|||
行5: | 行5: | ||
==foreach== | ==foreach== | ||
− | range = 1.. | + | range = 1..3 |
range.each do |i| | range.each do |i| | ||
print("i=", i) | print("i=", i) | ||
+ | end | ||
+ | |||
+ | ==文字列foreach== | ||
+ | names = ["taro", "jiro", "sabu"] | ||
+ | for name in names | ||
+ | print("name=", name) | ||
end | end |
2017年11月7日 (火) 00:20時点における版
for
for i in 1..3 do print("i=", i) end
foreach
range = 1..3 range.each do |i| print("i=", i) end
文字列foreach
names = ["taro", "jiro", "sabu"] for name in names print("name=", name) end