Do .. Loop not looping
1885
Posts: 11
I just started coding with a BOE-BOT bs2. "Board of Education"
this code only does 1 iteration.
Should it LOOP indefinitely?
' {$STAMP BS2}
'($PBASIC 2.5)
c VAR Word
DEBUG "PROGRAM RUNNING"
DO
c = c + 1
DEBUG ? c
PULSOUT 13,650
PAUSE 20
LOOP
this code only does 1 iteration.
Should it LOOP indefinitely?
' {$STAMP BS2}
'($PBASIC 2.5)
c VAR Word
DEBUG "PROGRAM RUNNING"
DO
c = c + 1
DEBUG ? c
PULSOUT 13,650
PAUSE 20
LOOP
Comments
Also,
-Phil
Check the color coding in your Stamp editor. Are DO and LOOP shown in automatic blue caps (good) or black (bad)? Black means it's not recognized as a command for some reason.
When in doubt, erase your PBASIC directive and re-enter using the button in the editor.
Edit: Good catch on the misplaced paren, PhiPi!
I can't believe how long I fiddled around with it before I noticed.the lack of color coding
'{$STAMP BS2}
'{$PBASIC 2.5}
c VAR Word
DEBUG "PROGRAM RUNNING"
DO
c = c + 1
DEBUG ? c
PULSOUT 12,750
PAUSE 20
LOOP
Curly brackets: imperative!
Heh... the old "Well =that= can't be wrong." mistake. ;-)
@
Though I have clicked the wrong button before and not noticed...
I had thought I was in the same boat, as I had just hooked up my first couple of circuits (I just got my Stamp Homework Board yesterday), and could not get it to loop at all. It would go once through and stop. I tried both a DO and FOR loop, same deal. I saw the note saying that on older computers you sometimes need to put a DEBUG statement right after the compiler directives. I tried that. Then I came on here and found this thread, so I double-checked my curly brackets, and made sure all my keywords were their correct colors--it all checked out. I was stumped, and beginning to panic a bit. I wondered if perhaps my PC was SO old that it just couldn't pass tokens through properly at all (my Dell is 14 years young).
Then I noticed the END statement at the end of my code block, right before the NEXT statement. D'Oh!!
You see, I had cut&pasted the code from my very first program, which was a "Hello, World!" test. I guess I grabbed a bit too much code!
Everything is working great now, and I'm having a blast cruising through the tutorials.