This is one of those times when I'll never understand why some things in
programming start counting at 1 and some things start counting at 0.

I, too, have several similar loops in some of my scripts, but I opted for
the more readable format of saying:

t.length.times { |x|
   puts t[x][0]
}

I just can't be bothered with loops like "1.upto(t.length) {|x| puts x}"
which, technically, counts from the "first item" to the "last item", but
really x starts counting at 0 and goes to (length - 1).  This might be
convenient if you are working with arrays but not a whole lot else.

Paul C.



On 23/01/07, Chris McMahon <[EMAIL PROTECTED]> wrote:

On 1/22/07, mi <[EMAIL PROTECTED]> wrote:
> t = [["a", "b"], ["aa", "bb"]]
>
> 0.upto (t.length) { |x|
>     puts t[x][0]
> }
>
> For some reason i'm getting the following error at the end of the loop,
> any idea WHY???

0.upto (t.length-1) { |x|
     puts t[x][0]
}

should do it, but I think you figured that out.

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to