Newbie to Stamps - code question
RonM
Posts: 8
I'm going thru the WAM book with the BOE USB board and a BS2 revC. I'm using PBasic 2.5. Servo examples but the issue I have is not with the servo.
When I try to execute a For loop using a step of -1, it does not seem to work as I expect. What appears to happen is:
a. It steps forward by 1 and then
b. drops thru
So if I have :
i VAR WORD
FOR i = 1000 TO 500 STEP -1
·· ' do something
NEXT
It executes what is in the for loop once but the value of "I" when I debug it is 1001.
PS. Software developer by trade.
Thanks,
Ron
·
When I try to execute a For loop using a step of -1, it does not seem to work as I expect. What appears to happen is:
a. It steps forward by 1 and then
b. drops thru
So if I have :
i VAR WORD
FOR i = 1000 TO 500 STEP -1
·· ' do something
NEXT
It executes what is in the for loop once but the value of "I" when I debug it is 1001.
PS. Software developer by trade.
Thanks,
Ron
·
Comments
Here is an explanation of valid StepValue arguments from the FOR...NEXT entry of the Help file.· It looks like the minus sign is only valid with the BS1,and not needed for the BS2 models; just having your StarValue greater than your EndValue is sufficient:
[*]StepValue is an optional variable/constant/expression* (0 - 65535) by which the Counter increases or decreases with each iteration through the FOR...NEXT loop. On the BS1, use a minus sign (-)† in front of the StepValue to indicate a negative step. On all other BASIC Stamps, if StartValue is larger than EndValue, PBASIC understands StepValue to be negative, even though no minus sign is used.
Hope you are having fun with WAM.
-Stephanie Lindsay,
Editor, Parallax Inc.
Using BS1 we could step using a negative step (-1, -2, -3, -4, etc) . But any Stamp after the BS1 (I'm new so bear with me on this), a negative step is assumed at it can only be by "-1". There is no way of stepping -4. Sorry to be a pain, I'm a software guy and once I get my hands around the syntax, I'll hit my comfort level.
For i =1000 to 500 step 5
will count down from 1000 in steps of 5 to 500.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
-Stephanie