Since it doesn't look like the value of x never actually changes, there are two possible ways to rewrite this. Either x >= 10 before the loop starts, then it will never be run, and it can simply be replaced with nothing. Otherwise, it's an infinite loop, and the most idiomatic way to write that is
loop do
search = Google::Search::Web.new
search.query = 'china'
search.start = x
end
If you don't know the value of x beforehand, you can simply make the loop conditional:
loop do
search = Google::Search::Web.new
search.query = 'china'
search.start = x
end if x < 10
If x is a message send whose method changes its return value, then I don't see any obvious way to improve your code other than removing the superfluous braces.
xanywhere. So if x < 10 at the loop start, the loop will run infinitely. If x >= 10 at the loop start, it will not run at all.whileis not used in Ruby as much as a loop with discrete start and end points. If you are conditionally incrementing yourxvalue, then awhileloop is fine because you don't have a fixed number of loops you have to run. Instead you'd be looping until 10 occurrences of that condition have occurred. Most of the time we want a fixed number of loops, but sometimes we want a fixed number of conditions, and only you can determine that.