# The evils of 0.each

**URL:** <https://www.ruby-forum.com/t/the-evils-of-0-each/48568>\
**Category:** Ruby\
**Created:** [November 22, 2005, 9:10am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568 "2005-11-22T09:10:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 22, 2005, 9:10am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568/1 "2005-11-22T09:10:58Z")

</div>

Why doesn’t 0 (Fixnum) support .each ?  
1 does, so does 2, 20, 200, and so on.  
Why not 0? Why doesn’t 0.each simply do something 0 times?

NYARGH!

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 22, 2005, 9:14am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568/2 "2005-11-22T09:14:59Z")

</div>

Lady Michelle B. wrote:

> Why doesn’t 0 (Fixnum) support .each ?  
> 1 does, so does 2, 20, 200, and so on.  
> Why not 0? Why doesn’t 0.each simply do something 0 times?
> 
> NYARGH!

Probably a bug.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 22, 2005, 9:35am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568/3 "2005-11-22T09:35:07Z")

</div>

Hi,

At Tue, 22 Nov 2005 17:07:25 +0900,  
Lady Michelle B. wrote in [ruby-talk:166943]:

> Why doesn’t 0 (Fixnum) support .each ?

Because Fixnum doesn’t have the method `each’.

> 1 does, so does 2, 20, 200, and so on.

All of them don’t.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 22, 2005, 9:31am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568/4 "2005-11-22T09:31:06Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), Lady Michelle B. wrote:

> Why doesn’t 0 (Fixnum) support .each ?  
> 1 does, so does 2, 20, 200, and so on.  
> Why not 0? Why doesn’t 0.each simply do something 0 times?

1#each doesn’t exist either.

You’re probably thinking of #times, which _is_ defined for 0, 1, 2, …

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 22, 2005, 9:51am UTC](https://www.ruby-forum.com/t/the-evils-of-0-each/48568/5 "2005-11-22T09:51:18Z")

</div>

> > Why doesn’t 0 (Fixnum) support .each ?  
> > 1 does, so does 2, 20, 200, and so on.

They don’t, because they’re single items, not lists, sets or something.

> > Why not 0? Why doesn’t 0.each simply do something 0 times?

Because 0.times { } does that.  
alternatively, Range#each works.
