- Home
- Academy BASIC
- Freshman
- Academy BASIC: 103 - Writing Your First BASIC Program
Academy BASIC: 103 - Writing Your First BASIC Program
- By chronodev (Ron)
- Published 11/2/2008
- Freshman
- Unrated
Prerequisites: Have VICE or another C64 Emulator installed. Instructions for installing VICE were given in module 102.
Outcome: Understand how to write a simple program.
Suggested time to complete this module: 30 minutes
It has long been a tradition amongst programmers that the first program they write when learning a new programming language is a program that displays a message saying "Hello World!". And we are certainly not planning on being the first to deviate from this longstanding tradition and incur the programmers' union wrath upon us.
In Commodore BASIC, it is very easy to write this program. You will do it using a single line of code! (In some other programming languages, many more lines are required for this type of program.)
So let's get to work.
Launch your console.
Type in the following line and press Enter: (Recall that SHIFT-2 writes the double quotes)10 PRINT "HELLO WORLD!"
That's it! You have now officially joined the cult of programmers. But don't put Programmer on your resume just yet, there is still a long way to go in this journey.
But wait a moment... you might be thinking, this program did not do anything! The only Hello World I see on the screen is the one that I myself typed! And you are correct in your observation. The program has been written and sits in the computer's memory, but if you want to see the results you have to run it. So let's do it. Type the following command into the console:RUN
The message Hello World! will now show in the screen. Congratulations!
Here is what your console should look like at this time:
If you had made a mistake in your program- for example, you misspelled PRINT, you will see a message saying ?SYNTAX ERROR IN 10.
What this message means is that the computer could not understand what you said. But don't get discouraged, you will see that message a lot during your programming life, and especially at the beginning when you are still learning. Heck, I still get these all the time (for example, because of misspellings) and I've been programming ever since I was a kid!
If this happened to you, just enter the code again, and then type Run
10 PRINT "HELLO WORLD!"
RUN
If you still are having any sorts of difficulties getting Hello World! to display, head over to our Forums where you will get help from the community.
Now let's expand our program a little. Type in the following lines of code:20 PRINT "THIS IS MY FIRST"
30 PRINT "BASIC PROGRAM"
RUN
The numbers 10, 20 and 30 are the line numbers. Why did we use 10, 20 and 30 and not 1, 2 and 3? Can you take a guess? We will discuss line numbering in a later module.
Your console should now look something like this:
This program doesn't do much, just prints out some text. But in the next module, you will write your first interactive program!
Homework:
Add more lines to your program. Have it print a short story... or a poem... or maybe a Haiku. Make your program at least 10 lines long. You will be doing this by adding additional lines of code with PRINT statements. This is to get you more comfortable with coding.
Spread The Word
Article Series
-
Academy BASIC: 103 - Writing Your First BASIC Program