For loops -- for months use i in 1...13?

I use a a for loop to populate an array of months each element
containing another array of days in that particular month. For examply
months[1][0] would be february 1st for whatever year it is. If I
populate the array @months using for i in 1…12 it does not include
December in the output when I do:

<% for month in @months %>
<% for day in month %>
…output here…
<%end%>
<%end%>

However, when I populate @months usins for i in 1…13, it includes
december? Did somebody add another calendar month that I don’t know
about, does for do everything accept the last number in the list, or is
something else going on here???

Confused,

Sam

Sam W. wrote:

<%end%>
<%end%>

However, when I populate @months usins for i in 1…13, it includes
december? Did somebody add another calendar month that I don’t know
about, does for do everything accept the last number in the list, or is
something else going on here???

LOL (no insults intended)…

Actually array indices start at 0. So months[0] will give you Jan.

Long
www.edgesoft.ca

On Oct 23, 2006, at 12:11 PM, Sam W. wrote:

<%end%>
<%end%>

However, when I populate @months usins for i in 1…13, it includes
december? Did somebody add another calendar month that I don’t know
about, does for do everything accept the last number in the list,
or is
something else going on here???

When creating a range in ruby … will give you an inclusive range
(including your final value) and … will give you an exclusive range
(excluding your final value)

So

1…12 -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

1…12 -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

You can find more on ranges at:

http://www.ruby-doc.org/core/classes/Range.html

James.


James S. : Web D.
Work : http://jystewart.net
Play : http://james.anthropiccollective.org

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs