Shop OBEX P1 Docs P2 Docs Learn Events
Careful stepping backwards... — Parallax Forums

Careful stepping backwards...

RaymanRayman Posts: 14,877
edited 2009-02-05 02:54 in Propeller 1
Just picked up on a Spin oddity after all these months...· I'm sure many people already know this but:

repeat j from 4 to 1 step -1 

doesn't work the way I expected, the loop only runs once.·
To make it go all four times, you have to write this:

repeat j from 4 to 1 step 1 

I'm sure this makes perfect sense to Chip, but just seems wrong to me...

Comments

  • CJCJ Posts: 470
    edited 2009-02-05 01:20
    the direction is automatic, only the size is needed <---I think this is the thinking behind this oddity, -1 is a really big step with the way the numbers are stored 2^32-1 smile.gif
    I think 1 is the default, and can be omitted

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • kwinnkwinn Posts: 8,697
    edited 2009-02-05 02:54
    The way it works makes perfect sense to me. The direction is explicitly implied in the statement. The only surprise is that the compiler is written to do what any child would do if told to count from 4 to 1. Kudos to whoever was responsible.
Sign In or Register to comment.