repeat while variable incrementation
fingerae
Posts: 15
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!
·
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
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.