previous |
start |
next
Avoiding Off-by-1 Error
- Run through a simple example:
target balance = $20,000, interest rate 50%
after one year: balance = $15,000
after two years: balance = $22,500
Therefore: year must start at 0
- interest rate 100%
after one year: balance = $20,000
loop should stop
Therefore: must use <
- Think, don't compile and try at random
previous |
start |
next