# Re: increasing counter whithin loop?

**URL:** <https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/96079>\
**Category:** Ruby\
**Created:** [December 8, 2005, 4:38pm UTC](https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/96079 "2005-12-08T16:38:07Z")\
**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, 4:38pm UTC](https://www.ruby-forum.com/t/re-increasing-counter-whithin-loop/96079/1 "2005-12-08T16:38:07Z")

</div>

> Hi Simon,

Hi Steve,

> I just ran your code, and got the exact output you got, but I  
> don’t understand  
> a bit of it.

😕

> First, I’m unclear as to the use of variables starting with  
> colon. What are  
> they, when are they used?

actually these aren’t variables but values, symbols to be  
specific:

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref\_c\_symbol.html](http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_symbol.html)

they aren’t used for any purpose in this example, the array just  
had to contain something.

> Also, are prv, this and nxt just any old variables, or are  
> they somehow  
> supplied by enumerator?

no they are not supplied by enumerator, each\_cons yields arrays  
do the block (containing 3 elements in this case).

because of the magick of ruby’s assign operator you can write

a, b, c = [1, 2, 3]

which is equal to

a, b, c = 1, 2, 3

or

a = 1; b = 2; c = 3

this is used here to give the 3 elements of the array yielded by  
each\_cons more meaningfull names.

> Is variable a a string, an array, or something else?

an array. […] creates arrays, see

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut\_containers.html#UA](http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html#UA)

> Why did you place an array containing only nil before and  
> after a in the  
> parentheses?

because, well because I would have missed the first and the last  
element of a otherwise. (I would have seen them in ‘prv’ or ‘nxt’  
but never in ‘this’)

> Thank you for this code. When I asked my question about how  
> to stop writing  
> Ruby with a Perl accent, I was hoping to understand  
> constructs like this one.  
> I have about 8 days experience with Ruby and so have some  
> catching up to do.

just hang on

cheers

Simon
