DO...LOOP
(Statement)
Repeat a block of statements while a condition is True or until a condition becomes True.
DO [{WHILE|UNTIL}[<conditional expression>]]
:
LOOP
Or
DO
:
LOOP [{WHILE|UNTIL}[<conditional expression>]]
DO WHILE and DO UNTIL are pretest loops.
LOOP WHILE and LOOP UNTIL are posttest loops.
A WHILE statement executes repeatedly while a condition is true (not 0), an UNTIL statement, until a condition becomes true.
In the expression specified by <conditional expression>, if the right-hand side is omitted, the system evaluates whether or not the value is true (not 0).
If <conditional expression> is omitted, the condition will be assumed as true (not 0). As a result, the WHILE statement falls into an infinite loop. An UNTIL never executes in a pretest loop and it executes only once in a posttest loop.
Although there is also a WHILE...WEND statement that is functionally equivalent to the DO WHILE...LOOP statement, using only DO WHILE...LOOP is recommended.
Although there is also a REPEAT...UNTIL statement that is functionally equivalent to the DO...LOOP UNTIL statement, using only DO...LOOP UNTIL is recommended.
WHILE and UNTIL can be omitted, but the loop becomes infinite.
DEFINT li1, li2, li3, li4, li5, li6, li7, li8, li9
|
|
DO WHILE li1 > li2
|
'Repeat in a pretest loop
|
IF li1 = 4 THEN EXIT DO
|
'If li1=4, exit from DO...LOOP
|
FOR li3 = 0 TO 5
|
'Repeat the process of FOR...NEXT 5 times
|
FOR li4 = li5 TO li6
|
'Repeat the process of FOR...NEXT while adding 1 to the
'value of li5 each time the process is done until li5
'becomes the value of li6
|
FOR li7 = 1 TO li8 STEP 2
|
'Repeat the process of FOR...NEXT while adding 2 to the
'value starting with 1 each time the process is done
'until the value becomes li8
|
IF li2 = 2 THEN EXIT FOR
|
'If li2=2, exit from FOR...NEXT
|
DO WHILE li2 < li9
|
'Repeat in a pretest loop
|
GOSUB *samp2
|
|
li9 = li9 + 1
|
|
LOOP
|
'Call a GOSUB *samp2 statement while li2 < li9
|
NEXT li7
|
'Repeat
|
NEXT
|
'Repeat
|
NEXT
|
'Repeat
|
li9 = 0
|
|
DO
|
'Repeat in a posttest loop
|
GOSUB *samp2
|
|
li9 = li9 + 1
|
|
LOOP UNTIL li9 < 5
|
'Call a GOSUB *samp2 statement until li9 < 5
|
LOOP
|
'Repeat
|