Quoting Hank Gong <hankgong / gmail.com>:

> And also I think it's not easy to think every loop as recursive
> way.

> For example it's very difficult to write max function by
> recursive function.

iterative:

 def max( *values )
   case values.size
   when 0
     nil
   when 1
     values[0]
   else
     i = 1
     max = values[0]
     while i < values.size
       max = values[i] if values[i] > max
       i = i + 1
     end
     max
   end
 end

recursive:

 def max( *values )
   case values.size
   when 0
     nil
   when 1
     values[0]
   else
     max_helper( values, 1, values[0] )
   end
 end

 def max_helper( values, i, max )
   if i < values.size
     max = values[i] if values[i] > max
     max_helper( values, i + 1, max )
   else
     max
   end
 end

-mental