Tuesday, September 11, 2007

Off by one

I hate being off by one. It happens a lot with loops and I had it happen again today.

I had

for(int i=0; i < payments.length-1; i++)

length is not zero based so I need to loop from 0 to length not inclusive. However I was one short.

The fix was simple.

for(int i=0; i < payments.length; i++)