When is 0 a -1 - again!
This code snippet ends up with BCDIndex = 0
Why?
When tested to 0 BCDIndex = 15.
I am sooo confused....
Clear_BCD:
DEBUG "Clear_BCD",CR
· FOR BCDIndex = MAXBCD - 1 TO 1
····· DEBUG ? BCDIndex
····· BCDDigit(BCDIndex) = 0········ ' clear all digits
· NEXT
· DEBUG ? BCDIndex
· STOP
RETURN
Why?
When tested to 0 BCDIndex = 15.
I am sooo confused....
Clear_BCD:
DEBUG "Clear_BCD",CR
· FOR BCDIndex = MAXBCD - 1 TO 1
····· DEBUG ? BCDIndex
····· BCDDigit(BCDIndex) = 0········ ' clear all digits
· NEXT
· DEBUG ? BCDIndex
· STOP
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Joshua Donelson
www.parallax.com
Right now it works but needs some refinement.
I think posting the whole program for such simple question is unnecessary.
Actually I was after the BCDIndex value to be set to 0 and though that I could save one line of code doing the loop "backwards"! I am pretty cheap!!
I like your explanation – makes perfect sense.
The moral of the story – check the loop counter to make sure it is what you expect!
Thanks guys.
!