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

Do Loop

dbrosedbrose Posts: 7
edited 2011-04-08 08:30 in Learn with BlocklyProp
For my project in school I am writing a program that requires loops, but I need to specify the number of repetitions, does anyone know how to make a 'Do-loop' with a specific number of repetitions?

Comments

  • Mark KiblerMark Kibler Posts: 546
    edited 2011-04-05 08:55
    OK, here's what I found on another thread. It may not exactly answer your question but it will get you closer to an answer.


    Here's what someone else replied to a similar question. The program code is posted below their answer

    You could use a DO.. WHILE LOOP and a variable to count the number of times the loop executes. I have attached a piece of sample code that will enter a DO...WHILE LOOP if the status pin equals zero. While in the DO...WHILE LOOP, the "TimeOut" Variable increments every time the loop is executed. The "IF" statement breaks the loop if the timeout variable accumulates a value of 20000. The reason I chose 20000 for the timeout is because the loop pauses for one millisecond, therefore, the loop will be exited after approximately 20 seconds.

    Program code:

    ' {$STAMP BS2p}

    ' {$PBASIC 2.5}

    Status PIN 0

    TimeOut VAR Word

    TimeOut = 0

    DO WHILE Status = 0
    IF TimeOut = 20000 THEN EXIT
    PAUSE 1
    TimeOut = TimeOut + 1
    LOOP

    DEBUG "Status Pin HIGH. Connection established", CR

    END


    Hope this helps,

    Mark
    ARLISS Team New Hampshire
    :cool:
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2011-04-05 11:02
    Hi dbrose,

    You could also you a FOR...NEXT loop to accomplish this task. You can read up on this and the DO...WHILE loop in the BASIC Stamp Syntax and Reference Manual.

    Best of luck!

    -- Jessica
  • dbrosedbrose Posts: 7
    edited 2011-04-08 08:30
    Thanks for all your help, we were able to use your advise to finish our code.
Sign In or Register to comment.