Shop OBEX P1 Docs P2 Docs Learn Events
repeat while variable incrementation — Parallax Forums

repeat while variable incrementation

fingeraefingerae Posts: 15
edited 2008-12-10 07:19 in Propeller 1
A typical programming structute I am used to in other languages looks like the following:

i:=1
repeat while i<=10
· i++

This looks to me like it would repeat 10 times.· However, when I try to implement that structure in my spin code, i is set to -1 as soon as the loop is entered or looped, so incrementation is not possible.· Why does this happen?· In the "REPEAT" section of the Propeller manual, there is a similar structure with one additional line of code.


byte[noparse][[/noparse]$7000][noparse][[/noparse]X] := 0 'Increment RAM value


Why is this line necessary?

Thanks!







·

Comments

  • BradCBradC Posts: 2,601
    edited 2008-12-10 07:16
    fingerae said...
    repeat while i<=10

    A common mistake. <= is an assignment operator.

    I think that should be ...
    repeat while i =< 10

    Doing it the way you are doing it will assign the boolean value to i when it does the first comparison.
    Another way to run that loop would be

    repeat i from 1 to 10
    xxxx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cardinal Fang! Fetch the comfy chair.
  • fingeraefingerae Posts: 15
    edited 2008-12-10 07:19
    Fantastic! Thanks so much!
Sign In or Register to comment.