J
Just Another Victim of the Ambient Morality
I don't know how to post the output of irb so I'll just have to describe
it but if I run the following code:
0.upto(10){ |i| puts i }
...I will get 11 lines of output. This iterates eleven times. Really?!
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 but if I run the following code:
0.upto(10){ |i| puts i }
...I will get 11 lines of output. This iterates eleven times. Really?!
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...