A New Counter
FOR...NEXT is a loop like DO...LOOP, but a FOR...NEXT
loop has its own counter built in. Try this:
CLS FOR I = 1 TO 10 PRINT I NEXT I
Much better than our last counter. This one stops on
its own after counting to 10.
A Color Chart
Here's a color chart program using a FOR...NEXT loop.
CLS FOR I = 1 TO 15 COLOR I, 0 PRINT I; "*** COLOR ***" NEXT I
STEP
FOR...NEXT can also do "step counting". Try this:
CLS FOR I = 2 TO 20 STEP 2 PRINT I NEXT I
That will count by 2's from 2 to 20. STEP tells
QBASIC what to count by. Try changing it to count by
10's from 10 to 100.
FOR...NEXT can also count backwards if you use a
negative STEP value:
CLS FOR I = 10 TO 1 STEP -1 PRINT I SLEEP 1 NEXT I PRINT "BLAST OFF!"
"SLEEP 1" tells QBASIC to wait for
one second, then continue.
Source: http://jpsor.ucoz.com |