View Full Version : Do Loop

04-05-2011, 03:25 PM
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?

Mark Kibler
04-05-2011, 03:55 PM
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
TimeOut = TimeOut + 1

DEBUG "Status Pin HIGH. Connection established", CR


Hope this helps,

ARLISS Team New Hampshire

Jessica Uelmen
04-05-2011, 06:02 PM
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 (http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf).

Best of luck!

-- Jessica

04-08-2011, 03:30 PM
Thanks for all your help, we were able to use your advise to finish our code.