### Re: My First Program

```James Powell wrote:

> if leap = 0 then
>     if month > 2 then
>         day = day - 1
>     end if
>     if day = 0 then
>         month = month - 1
>         day = maxdays[month]
>     end if
> end if

Why not factor the rest of the code? This stuff:

> if day < 32 then
>     month = 1
> elsif day < 60 then
>     month = 2
>     day = day - 31
> elsif day < 91 then
>     month = 3
>     day = day - 59
> elsif day < 121 then
>     month = 4
>     day = day - 90
> elsif day < 152 then
>     month = 5
>     day = day - 120
> elsif day < 182 then
>     month = 6
>     day = day - 151
> elsif day < 213 then
>     month = 7
>     day = day - 181
> elsif day < 244 then
>     month = 8
>     day = day - 212
> elsif day < 274 then
>     month = 9
>     day = day - 243
> elsif day < 305 then
>     month = 10
>     day = day - 273
> elsif day < 335 then
>     month = 11
>     day = day - 304
> elsif day < 366 then
>     month = 12
>     day = day - 334
> end if

can be replaced with a loop similar to the one you already have, and use the
array of months:

-- START OF CODE

-- sum of days that past, not including current month
daysPast = 0

-- cycle through the months
for i = 1 to length( maxdays ) do

-- does the day fall within this month?
if day <= daysPast + maxdays[i] then
-- save the month
month = i

-- calculate the day
day = day - daysPast

-- leave the loop
exit

else

-- add the total of prior days
daysPast = daysPast + maxdays[i]

end if

end for

-- END OF CODE

I haven't bothered to test it, but you get the idea.

-- David Cuny
```