Do Loop in spin?
10gigbill
Posts: 79
I have a 9600 baud stream party-lined to several (5) props
Each prop has a one character “address” (unique char only used for addressing) that will have a 5 character command following for that address. I want to have a timer in the prop so that once it sees it’s address and starts to collect it’s 5 characters it will not hang if the party-line is interrupted. That is it should receive the characters in say .1 seconds. If not it should go back to looking for a new command string.
As soon as I see my address I start the timer and collect the next
5 characters while timer is not timed out. Do while….
BUT AAAARRRRGGGGGG…. There is no Do loop …..?
Sorry I’m new at this spin thing
Thank you for your support.
Bill
Each prop has a one character “address” (unique char only used for addressing) that will have a 5 character command following for that address. I want to have a timer in the prop so that once it sees it’s address and starts to collect it’s 5 characters it will not hang if the party-line is interrupted. That is it should receive the characters in say .1 seconds. If not it should go back to looking for a new command string.
As soon as I see my address I start the timer and collect the next
5 characters while timer is not timed out. Do while….
BUT AAAARRRRGGGGGG…. There is no Do loop …..?
Sorry I’m new at this spin thing
Thank you for your support.
Bill
Comments
In SPIN, the REPEAT loop does the job of all the usual DO/WHILE/UNTIL/FOR loop constructs. Check page 293 of the Propeller manual (v1.01).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina
I'll give this a try and maybe by tomorrow I'll get a little farther down the line on my project.
Repeat (while...) hummmm......
thanks
The condition is checked at the beginning in one case and it's checked in the end in the other case.
So, to turn a while loop into a do loop you'd simply choose a condition which is true in the first iteration.
A slightly modified method is to OR a first-time flag with the normal "do" condition as follows:
first := true
repeat while first OR <condition statement>
· first := false
· ...
· next
· ...
· next
· ...
Another thing is that "repeat from" loops always execute at least once.· Also the "step" value is not the actual increment used, but it is a multiplier of the computed step value.· The following examples yields unexpected results unless you understand how the step value is used.
for i from 0 to -10 step -2
This will execute once with the final value of i being 2.· If I wanted to step through values of 0, -2, -4, -6, -8 and -10 I would need to use the following statement.
for i from 0 to -10 step 2
Also, a C statement of "for (i = 0; i <= num; i++)" does not translate directly to "repeat i from 0 to num".· If num is negative Spin will decrement "i" instead of incrementing it.· The C statement would need to be written in Spin as follows
if (num => 0)
· repeat i from 0 to num
·