✔ 最佳答案
圖片參考:
http://www.svatopluk.com/qbtutor/next.gif
Loops
圖片參考:
http://www.svatopluk.com/qbtutor/star.gif
"Loops" make it easier to do an action multiple times. There are at least four types of loops: IF...GOTO , WHILE...WEND , DO...LOOP , and FOR...NEXT .
IF...GOTO
This program uses IF...GOTO to create a loop:
x = 10
start:
PRINT x
x = x + 1 (This adds 1 to x)
IF x < 15 THEN GOTO start
Output:10
11
12
13
14
WHILE...WEND
The WHILE...WEND commands continue a loop until a specified expression is false.
To use WHILE...WEND :Place an expression after WHILE
Enter a list of commands
Place WEND at the end
Run the following:x = 10
WHILE x < 15
PRINT x
x = x + 1
WEND Output (same as in previous example):10
11
12
13
14
DO...LOOP
DO...LOOP is exactly the same as WHILE...WEND , except it has at least two slight advantages. With DO...LOOP you can:Loop until an expression is true
Loop at least one time regardless of whether the expression is true or not.
To use DO...LOOP :Specify whether the loop continues "while" the expression is true or "until" the expression is true, using the WHILE and UNTIL statements, respectively.
Place an expression after WHILE / UNTIL
Enter a list of commands
Place LOOP at the end
The following uses the WHILE statement:x = 10
DO WHILE x < 15
PRINT x
x = x + 1
LOOP
This program uses the UNTIL statement:x = 10
DO UNTIL x = 15
PRINT x
x = x + 1
LOOP
They both output:10
11
12
13
14
If you place the expression at the end of the loop instead, the program goes through the loop at least once.x = 32
DO
PRINT x
x = x + 1
LOOP WHILE x < 5 This is the output because the loop was only gone through one time:32