What is the solution to this problem?


#1


#2

We cannot iterate a range in reverse. For that we need to use Numeric#step.

Using a for loop,

for i in 0..18
    next if i % 2 == 1
    print "#{18-i}"
end

Outputs,

1816141210864200..18

Using loop do,

i = 20
loop do
    i -= 1
    next if i % 2 != 0
    print "#{i}"
    break if i <= 0
end

Outputs,

181614121086420nil

Both of these are accepted solutions. There may be others, as well (being Ruby) so play with this awhile when you have time.