Jamie’s Qbasic Tutorial – Chapter 4


In this tutorial I am going to cover a few more basic commands to prepare for a tutorial on bitmapping. Anyway the commands I am explaining are


For ~ Next ~ Data ~ Read


There also a few other commands that are involved in bitmapping which are either not involved in the bitmapping I going explain or I have either explained in a previous chapter of this tutorial.


I will start this chapter of my Qbasic tutorial by explaining what a for-next loop is. Well a loop is something that happens over and over again. A for-next loop is a loop, which runs a fixed amount of times; there is also a do-loop which runs until a certain condition is met. Last of all there is a while wend loop, but I don’t know much about a while wend loop. Anyway I will go on to say how to use a for next loop. In a for next loop you use the for command to start the loop. After the for command you put your code and after the code goes the next command. Anyway when using a for next loop you need a variable. The for next command is counts. You decide Finally here’s the syntax for a for next loop:


For x = 1 to 10

Print x

Next x















In this example I have looped 10 times, and I have counted from 1 to 10 but I could have counted from 5 to 15 for example or 15 to 5 or even 5 to –5. But be careful because there is a limit to how much you count to. For more information check the Qbasic help files. Anyway you may have noticed I got Qbasic to print what it had counted to in this example. I did this by telling Qbasic to print x, the variable which I had chosen for Qbasic to use to tell me what it had counted to. Anyway that’s it for for next loops if you any questions about this just email me at mail@jatos.co.uk. Anyway I will now go onto data and read.




Anyway before you use the read statement you need to put some data in the memory. As I said earlier you do this with the data statement. Anyway here’s the syntax for the data statement:


Data <data>


You can either give it data from a variable or you can give the command some data that isn’t in a variable. You can also put multiple bits of data in the statement if you split the pieces of data up with a comma. For here’s four examples of the commands use:


Example 1:


Data 3, 3


Example 2:


Data variable


Example 3:


Data variable$


Example 4:


Data “hello world”


If you put all those examples in one program you will get a program which has the following pieces of data waiting to been read (assuming that variable$ is hi and variable is 5)






hello world


Anyway lets go onto the read statement. Before we go anywhere imagine there is a queue. Every time you use the data command, the data submitted joins the queue. If you of data in put multiple bits of data the data statement all the pieces of data join the queue separately.  This queue is made of data waiting to be read by the read statement. Once a piece of data has been read it leaves the leave. The data must be read into a variable. Anyway here’s the syntax for the read command:


Read var($)


Please note that you have to read the data into the correct type of variable or you will get an annoying error message.  Anyway here’s an example of the commands use assuming that we have the following data I our queue 1, 3, “hi”.



Read a

Read b

Read a$


Print a

Print b

Print a$

Read c

Print c


Anyway here the output (note the error message caused by me trying to read data that doesn’t exist)






Out of data


Please note that the error message would not appear exactly like I have put here. But that’s what it would do if, just like I did, you tried to read data that does not exist. However you will NOT get an error message if you don’t read everything in the queue before program exit.


Anyway that is it for this tutorial If you have any questions about what I said just email me at mail@jatos.co.uk.