Introduction

Show Index
So you want to learn how to program in BASIC eh?  Well you've come to the right place.

For your reference, on the right is a short list of some of the conventions that are used in this tutorial:

Now, in case you didn't know, perhaps we should start off with telling you what BASIC actually stands for: Beginners All-purpose Symbolic Instruction Code.  But you know what?  BASIC isn't just for beginners.  I've been using it for over 20 years!

Well, now that you know that useful bit of information, where should we begin?  Well a common thing that many programmers attempt to do their first time is to write "Hello World" on the screen.  We can do that.

BASIC commands used in the text are written as:
Gold
Code is written as:
green on black
Code that is included within the text is written as:
Green
Output sent to the screen is written as:
cyan on black
Input typed into the screen is written as:
white on black

Start up BlitzBASIC (or your compiler) and press the New page button (the first button on the left) to open up an empty page.  Type the following line into the new page:

Print "Hello World"

helloworld.png (6473 bytes)
Note that the double quotation marks must be around "Hello World"

If you execute (run) the above code (by pressing the rocket button in Blitz) then you should see this on the screen:

Hello World

However, depending on the compiler that you are using, what may have just happened for you is that you probably didn't see anything but a flash of something on the screen.  If this is what you experienced, it may be because once the computer had finished executing your one line of code and didn't find any more after that, it terminated the program (in other words, it closed the window that your program was running in).  In order to be able to actually keep "Hello World" printed on the screen long enough for you to read it we may need to add another line to the program.  One way we could do it is by typing this:

Print "Hello World"
Delay 2000
Note that there is no need to retype the Print "Hello World" line.  You only have to add the Delay 2000 line after the Print "Hello World" line.
However, make sure that Delay 2000 is on a separate line!

Which, upon executing, would:
1. execute the first line of the program, printing "Hello World" to the screen
2. execute the second line of the program, causing a delay of 2 seconds (Note: the Delay command uses 1/1000ths of a second, so we need 2000 of them)
3. terminate the program

This ends up allowing us enough time to read "Hello World" before the program ends.  You will also note at this time that the computer executes the lines of code from top to bottom.  This is important, because if it executed the delay first, we would see nothing on the screen and then just a flash of "Hello World" before the program terminated.

Another way we could keep "Hello World" on the screen long enough for us to read it is by typing in this:

Print "Hello World"
WaitKey()
Note that there is no need to retype the Print "Hello World" line.  Just erase the Delay 2000 line and type Waitkey() instead.

Which, upon executing, would:
1. execute the first line of the program, printing "Hello World" to the screen
2. execute the second line of the program, causing the computer to wait for you to press a key on the keyboard
3. (after you've pressed a key) terminate the program

This allows us to take as much time as we want to read "Hello World" before the program ends.  This would be a great thing to do if we had a lot of information on screen that the user needed to read.

 

Continue on to Variables.
Goto next lesson

 

If you've reached this page and there's no index on the left, Click here to show the Index Page