From: mental@... Date: 2005-12-13T03:58:22+09:00 Subject: Re: A question about recursive programming Quoting Hank Gong : > 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