我想知道是否有任何优雅的方法来实现以下方法的循环.我只能提出一个常规while循环(Java程序员)作为以下伪代码:
while x<10
search = Google::Search::Web.new()
search.query = "china"
search.start = x
end
Run Code Online (Sandbox Code Playgroud)
有人知道更好的方法吗?
许多选择:
# Will go 0..9
10.times do |i|
search = Google::Search::Web.new()
search.query = "china"
search.start = i
end
# Will go 1..10
1.upto(10) do |i|
search = Google::Search::Web.new()
search.query = "china"
search.start = i
end
# Will go 1..10
(1..10).each do |i|
search = Google::Search::Web.new()
search.query = "china"
search.start = i
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3394 次 |
| 最近记录: |