You should look at the Matz book The Ruby Programming Language page 137:

external or internal iterators


On Sep 20, 2008, at 9:50 PM, tekwiz wrote:

> I just used the new roodi gem to check out some of my code that has a
> lot of algorithmic code.  It gave me a number of issues with the
> phrase "Don't use 'for' loops. Use Enumerable.each instead."  I prefer
> for loops as opposed to using each simply because it's what I'm used
> to coming from C-style languages.
>
> Example:
>
> This is what I do:
>
>   for i in 0...str.size
>     ...
>   end
>
> This is what roodi would have me do
>
>   (0...str.size).each do |i|
>     ...
>   end
>
> Is there a real, substantive reason to use each instead of for? Or is
> it simply just a preference issue?
>
> Thanks,
> --
>      TekWiz
>
>