I am not seeing expected behaviour in a For Next loop with a step. Take the code below:
Main:
for FlashCount = 1 to 6 step 2
Set LED1 on
wait 500 ms
Set LED1 off
wait 500 ms
next FlashCount
set LED2 on
wait 1 s
Set LED2 off
goto main
I expect to see LED1 flash 3 times and LED2 flash once (using it to indicate start of next loop) But LED1 flashes 4 times per flash of LED2
Changing values produces: No step = 6 flashes; Step 2 = 4 flashes, Step3 = 3 flashes
I am using a 16F18877 dev board and latest GCB@SYN and a fresh install on Win10
What am I missing here? I have reasonable experince in programming since 1970's but usually, unexpected behaviour, is me not understanding the finer points of a new language or dialect or just simple stupidity :)
Have I been in isolation too long already??
TIA
Julian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks - yes I did try that and it does work.
I guess the 'next' test is looking for an 'equal to' rather than 'equal to' or 'greater than'?
In most Basics I have played with, I think => is the norm but thats fine, if I understand the issue I can work around it when needed.
Appreciate the reply.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For next with step is ok as you say Anobium if used correctly.
I don't like using case , to me it slows code. I don't know. Like using and to test multiple variables.
Is repeat until var=x more efficient than for next? or do loop until var=x
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not seeing expected behaviour in a For Next loop with a step. Take the code below:
Main:
for FlashCount = 1 to 6 step 2
Set LED1 on
wait 500 ms
Set LED1 off
wait 500 ms
next FlashCount
set LED2 on
wait 1 s
Set LED2 off
goto main
I expect to see LED1 flash 3 times and LED2 flash once (using it to indicate start of next loop) But LED1 flashes 4 times per flash of LED2
Changing values produces: No step = 6 flashes; Step 2 = 4 flashes, Step3 = 3 flashes
I am using a 16F18877 dev board and latest GCB@SYN and a fresh install on Win10
What am I missing here? I have reasonable experince in programming since 1970's but usually, unexpected behaviour, is me not understanding the finer points of a new language or dialect or just simple stupidity :)
Have I been in isolation too long already??
TIA
Julian
@Julian. You have not been locked up for toooooo long.
The FlashCount needs to be adapted. Consider the steps as defined 1-2-5-7 The step 6 is never encountered.
So does for FlashCount = 1 to 5 step 2 work? or, consider using Repeat 3 - End Repeat.
:-)
Thanks - yes I did try that and it does work.
I guess the 'next' test is looking for an 'equal to' rather than 'equal to' or 'greater than'?
In most Basics I have played with, I think => is the norm but thats fine, if I understand the issue I can work around it when needed.
Appreciate the reply.
Look at REPEAT and SELECT CASE.
:-)
For next with step is ok as you say Anobium if used correctly.
I don't like using case , to me it slows code. I don't know. Like using and to test multiple variables.
Is repeat until var=x more efficient than for next? or do loop until var=x