From: Xavier Noria Date: 2008-09-21T07:50:50+09:00 Subject: Re: for or each? On Sun, Sep 21, 2008 at 12:26 AM, Joe Wölfel wrote: > for i in 0...(a.size) > x += a[i] > end Hey that's not the for-version of #each, nobody iterates by index in dynamic languages unless he needs to. The message to the OP is: for versus each is a stylistic discussion in the sense that they are equivalent *if used the way I showed*. A regular loop over a collection using indexes is never used in dynamic languages because it is much slower than array indexing in C. That's the price you pay for such flexible estructures. In Ruby an array has nothing to do behind the scenes with a C array. That's why VHLLs provide specific efficient and concise collection iterators: # Perl foreach my $user (@users) { ... } # Ruby for user in users ... end # or users.each do |user| ... end # Python for user in users ... # Lisp (dolist (user users) (...))