Group: comp.lang.ruby


Subject: for loop
From: Just Another Victim of the Ambient Morality
Date: 11/21/2007 6:31:45 PM
"Martin Durai" <martin@angleritech.com> wrote in message news:f747d23ae4aecdcd871befcbebba0d09@ruby-forum.com... > Consider the following for loop in 'C' or 'c++' or 'java' > > for (i=namespaceEnd - 1; i >= 0; i--) > > Please help me with code to do the same functionality in ruby I'm surprised no one's suggested the obvious: namespace.reverse_each do |i| # Do something with i end ...this assumes you don't actually need an index, which is usually the case. It also assumes that namespaceEnd is the end of a container called "namespace," or some such... If you need the index, instead of the array, you'll have to do something wild and zany, like: namespace.reverse.each_index do |i| # Do something with i end ...does this help?