Shop OBEX P1 Docs P2 Docs Learn Events
Do .. Loop not looping — Parallax Forums

Do .. Loop not looping

18851885 Posts: 11
edited 2012-02-04 07:40 in BASIC Stamp
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

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-01-16 13:36
    There may be an issue with your PBASIC 2.5 pragma. Try enclosing it in {braces} instead of (parentheses). (I'm a little surprised that the program even compiled.)

    Also,

    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • ercoerco Posts: 20,256
    edited 2012-01-16 13:44
    Yes, it should loop indefinitely.

    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!
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-01-16 14:01
    I was was just testing it and that's the problem. It needs the ($PBASIC 2.5) changed to {$PBASIC 2.5}

    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 CRSRXY,0,2, ? c
    
        PULSOUT 13,650
        PAUSE 20
      LOOP
    
  • 18851885 Posts: 11
    edited 2012-01-16 14:08
    I made sure '{$PBASIC 2.5} was in curly brackets. All is good. thank you all!

    '{$STAMP BS2}
    '{$PBASIC 2.5}
    c VAR Word
    DEBUG "PROGRAM RUNNING"
    DO
    c = c + 1
    DEBUG ? c
    PULSOUT 12,750
    PAUSE 20
    LOOP
  • ercoerco Posts: 20,256
    edited 2012-01-16 14:24
    Curly fries: good.

    Curly brackets: imperative!

    :)
  • ajwardajward Posts: 1,130
    edited 2012-01-16 14:55
    1885 wrote: »
    I made sure '{$PBASIC 2.5} was in curly brackets. All is good. thank you all!

    Heh... the old "Well =that= can't be wrong." mistake. ;-)

    @
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-01-16 15:41
    You can use these nifty buttons to insert those directives. I've never caught the Editor using the wrong brackets. :)
    Though I have clicked the wrong button before and not noticed...

    pbasic.jpg
    315 x 157 - 14K
  • splinesmithsplinesmith Posts: 1
    edited 2012-02-04 07:40
    Thanks for this thread--it gave me things to look for. I'm posting what happened to me because it was kind of amusing (at least, NOW it is).

    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.
Sign In or Register to comment.