It's interesting that array access using 'each' seems to be much  
faster on my machine.  In C, indexed-based for-loops are slow.  It's  
faster to increment  pointers.  Maybe it's similar under Ruby's hood.

ruby 1.86 (OS X PPC)
Rehearsal --------------------------------------------------
for loop         1.200000   0.000000   1.200000 (  1.206533)
each             0.510000   0.000000   0.510000 (  0.511994)
----------------------------------------- total: 1.710000sec

                      user     system      total        real
for loop         1.190000   0.000000   1.190000 (  1.190023)
each             0.500000   0.000000   0.500000 (  0.508636)


ruby 1.9 (Same OS X PPC)
Rehearsal --------------------------------------------------
for loop         2.370000   0.010000   2.380000 (  2.376402)
each             1.770000   0.000000   1.770000 (  1.775798)
----------------------------------------- total: 4.150000sec

                      user     system      total        real
for loop         2.310000   0.010000   2.320000 (  2.316495)
each             1.780000   0.000000   1.780000 (  1.775958)

Joe

On 20 sept. 08, at 15:50, 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
>