# Re: increasing counter whithin loop?

**URL:** <https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/49746>\
**Category:** Ruby\
**Created:** [December 8, 2005, 10:48am UTC](https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/49746 "2005-12-08T10:48:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon.kroeger.ext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@simon.kroeger.ext](https://www.ruby-forum.com/u/simon.kroeger.ext)\
**Post date:** [December 8, 2005, 10:48am UTC](https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/49746/1 "2005-12-08T10:48:17Z")

</div>

> The each\_with\_previous was a very nice hint, thanks, even if I wasn’t  
> able to use it. I’d probably have to create each\_with\_prev\_and\_next.

Hmm, I still don’t know exactly what you realy want/need. If you just  
want to replace two instances of :b with double\_b, have a look at this:

* * *

require ‘enumerator’  
a=[:a, :b, :b, :c, :b, :d, :e]

## a[a.to\_enum(:each\_cons, 2).to\_a.index([:b, :b]), 2] = ‘double\_b’ puts a

(yes, of course this is completely without error checking and  
doesn’t work for more than one occurrence of :b, :b)

As I said, I’m not realy sure that’s what you are looking for…

cheers

Simon
