04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DO - WHILE<br />

<strong>Syntax</strong><br />

do<br />

program statements<br />

while condition<br />

• Statements - any group of commands to be run inside the loop.<br />

• Condition - can be a variable or expression<br />

Supported<br />

• BA - Supported.<br />

• BAN - Supported.<br />

• BAP - Supported.<br />

• BAP40 - Supported.<br />

Description<br />

The DO - WHILE loop executes commands nested inside of it will some condition is true. The<br />

condition can be any variable or expression that is tested every loop until it is false.<br />

Commands<br />

Notes<br />

1. In the programming world 0 is consider false. By default DO - WHILE will test this condition. If a<br />

stand alone variable is used for the test the loop will continue until its value equals 0.<br />

2. DO - WHILE will always run at least once since the condition is checked last in the loop.<br />

3. You can nest multiple DO - WHILE commands within each other. However you can not nest DO -<br />

WHILE with a WHILE - WEND together or the compiler will get the WHILE statements confused.<br />

Example<br />

Connect to the following program with the terminal window set to 9600 baud. The program will<br />

start counting up from 0 to 100. Once index reaches a value of 100 the condition is no longer true.<br />

The less than symbol < was used for the condition and 100 is no longer less than 100 making the<br />

condition false. Since DO - WHILE loops while a statement is true the program exits.<br />

;ALL - all_do_while.bas<br />

Index var word<br />

Main<br />

End<br />

Index = 0<br />

Do<br />

index = index + 1<br />

serout s_out, i9600,[0, “Counting: “, dec index]<br />

pause 75<br />

While index < 100 ;repeat until index is no longer less than 100<br />

serout s_out, i9600, [13,13, “Index = “, dec index]<br />

serout s_out, i9600, [13, “My condition is no longer true.”]<br />

serout s_out, i9600, [13, “Index is no longer less than 100”]<br />

99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!