The DO LOOP statement
The DO - LOOP statement executes a block of instructions while
or until a condition is true.
The syntax is:
DO
[List of
instructions]
LOOP UNTIL condition
is met
|
or
DO
[List of
instructions]
LOOP WHILE condition
is met
|
While a counter is automatically
incremented in the FOR - NEXT statement, you will have to increment the
counter yourself with the DO - LOOP statement.
Below is a comparison of the two
methods:
| The
two codes below are equivalent |
| FOR
- NEXT |
DO
- LOOP |
'This program displays a sentence 5 times
CLS
DIM counter AS INTEGER
FOR counter = 1 to 5
PRINT "Hello! How are you"
NEXT |
'This program displays a sentence 5 times
CLS
DIM counter AS INTEGER
counter = 0
DO
PRINT "Hello! How are you"
counter = counter + 1
LOOP UNTIL counter = 5 |
[ Previous Index
Next ] |