Shop OBEX P1 Docs P2 Docs Learn Events
Do loop / for next — Parallax Forums

Do loop / for next

Mike WMike W Posts: 105
edited 2008-05-30 11:46 in General Discussion
Both of these routines work, they write a degree character to location 0 of a LCD.
I noticed that the DO LOOP routine takes less space when compiled
Is that the only difference between them?
they both seam to work fine and do the same thing.
is their an advantage or disadvantage to using either
·
'

· tmpB4 = 0
· DO······················· ······························· ······························· ············ ·' write custom degree º character
·· READ DegreeSign + tmpB4, tmpB2·················· ··············· ··············· ' to location 0
··· LCD_OUT tmpB2··················· ······························· ··············· ' send the byte
···· INC tmpB4
· LOOP UNTIL tmpB4 = 9
'

·
'

· FOR tmpB4 = 0 TO 8······················ ······························· ··············· ' write custom degree º character
·· READ DegreeSign + tmpB4, tmpB2·················· ··············· ··············· ' to location 0
··· LCD_OUT tmpB2··················· ······························· ··············· ' send the byte
'NEXT··················· ······························· ······························· ··············· '
'


Thanks
Mike

Comments

  • BeanBean Posts: 8,129
    edited 2008-05-30 11:46
    Mike,
    · FOR...NEXT also checks for overflows/underflows that is why it takes more code.
    · If tmpB4 had to go from 0 to 255, then you would need "LOOP UNTIL tmpB4 = 256". Which of course would never be true.

    · You bring up a good point though...If the limit is a constant less than (256 - step), then there really isn't a need to check for overflows/underflows.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
Sign In or Register to comment.