From: Gary Wright Date: 2008-12-24T04:49:26+09:00 Subject: Re: Integer.step is inclusive?! On Dec 23, 2008, at 2:36 PM, Just Another Victim of the Ambient Morality wrote: > Why it does this is obvious. Integer.upto is inclusive so it > includes > both 0 and 10. However, am I the only one who thinks this is strange > behaviour? I mean, the ususal programming protocol is that the last > element > is not included (half-open sets, if you will) so the number of > iterations is > the difference between numbers. > Why did Ruby turn out this way? Thank you... It isn't really that Ruby is this way just that the method 'upto' is this way. There are several other ways to iterate over an integer range: >> (0..4).each { |i| puts i } 0 1 2 3 4 >> (0...4).each { |i| puts i } 0 1 2 3 >> 4.times { |i| puts i } 0 1 2 3 >> 0.step(4).each { |i| puts i } 0 1 2 3 4 >> 0.step(4,2).each { |i| puts i } 0 2 4