Tuesday, 2024-05-07, 4:54 AM

Welcome Guest | RSS

MainRegistrationLogin
Qbasic Home

Catalog categories
Qbasic Tutorial [31]

Rate my Site
Rate JPSor Site
Total of answers: 168

Main » Articles » Qbasic Tutorial

Chapter 16 - Qbasic Tutorial

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
Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 1901 | Rating: 0.0/0 |
Login

Qbasic Clock

Search

Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0


Copyright MyCorp © 2024