I would like to know if there is any elegant way to implement a loop for the following method. I can only come up with a regular while loop (Java programmer) as the following pseudo code:
while x<10
search = Google::Search::Web.new()
search.query = "china"
search.start = x
end
Someone knows a better way?
Do you mean to do something like this?
That will run the query with start at
1, then start at2, all the way up to start at9. The1..9syntax is a range, inclusive on both sides.UPDATE: The
(1..9).eachis probably the most idiomatic way to do this in ruby, but Jonas Elfström posted a cool link that quickly demonstrates some alternatives:http://alicebobandmallory.com/articles/2010/06/21/a-simple-loop