foo = [3, 6, 3]
for a in foo:
print a
Run Code Online (Sandbox Code Playgroud)
我怎么用红宝石做到这一点?
kch*_*kch 11
list = %w( a b c )
# there's a for statement but nobody likes it :P
for item in list
puts item
end
# so you use the each method with a block instead
# one-liner block
list.each { |item| puts item }
# multi-line block
list.each do |item|
puts item
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
543 次 |
| 最近记录: |