This is the "start here" page for a set which I hope will help you have fun programming your computer using the language called BASIC.
It this page is only "baby food" for you, please be patient. Some readers may not know as much as you do.
Please work your way through it anyway, just to get us all on the same page.
This page assumes that your computer has been set up for doing BASIC programming. If it hasn't, I (at 21 Feb 25, plan to!) do a guide to setting it up. (link to come- please complain of you see this and need the guide... details for contacting me below.
This page, and the others in the set, will be most helpful to people using the environment from www.bbcbasic.co.uk/bbcbasic.html, using the SDLIDE (one of two IDE's on offer), all of that free, and for various platforms.
But! I hope that much of it will also be helpful to people learning BASIC in a different environment. (The BASIC I am enthusiastic about is very close to the excellent BBC BASIC which was hugely important in the early days of computers in home and schools in the UK.)
So! Assuming you DO have an BASIC programming environment in place...
Launch the program that helps you write programs in BASIC, the "IDE". You should see...
Type in what you see below... the colors happen by themselves. The indent happens by itself. If you've used other BASICs, don't be alarmed by the lack of line numbers. (They were a "feature" of the Bad Old Days, from which we have, happily, MOVED ON!)
If you don't see the colors shown here on your screen, look closely at what you've typed. Put a small typo in "PRINT" to see the color change when something isn't quite right.
Then click on the green "arrow" (see image) to run the program.
If all is well, a second window will pop up. In it you should see "Hello". (Without the "s.) That's there because of your (very small!) program!
The second window is showing what appears when your program runs.
That window is simulating the screen of the computer BBC BASIC first ran on. With the BBC computer, we didn't have anything like the first screen where, now, we write the program. We wrote the programs on the BBC computer, and ran them there.
Notice the ">" and the flashing underscore beneath the word "Hello" in the new screen. They say that "the computer" (i.e. the one simulated in the second window) has finished what it was told to do, and is now waiting for further commands. Type LIST and your program will appear on the screen. Type RUN, and the program will run again.
For now, type QUIT (or click on the X in the upper right-hand corner) and the second window, the simulation of the computer the program ran on, will go away, and you'll be back in the IDE. You'll need to do this each time you've run your program... until you are putting something mildly clever into your programs to save you the nuisance.
You've just written a program! And made it "go". (The usual word is "run".)
A "program", or "code", is just some instructions that can be understood by the computer.
Computers are NOT "smart"... but they are very reliable. They do what they've been told to do. Not what you think they "should" do. Not what you MEANT to tell it to do. They do what your code says you wanted it to do!
The program for any particular need... be it work or play... is written once by a programmer, and then saved. After that, anyone can load the program and execute it. (We'll come to saving in a later lesson.)
Don't underestimate what you've just done.
All the programs you write after this will just be more of the same. You will learn new words. You will learn clever ways to do things with the words. But even the tiny program above shows you many of the "secrets" of computer programming!
Except for one other major thing...
Variables are a place where you can put things. We'll use one to extend our existing program.
(In this context, "variable" is a noun, a thing. The word is sometimes used as an adjective, a describing word. If you say "The weather is going to be variable", you are saying that it will be changeable.)
Beneath the PRINT "Hello" we already have, add...
INPUT MyNumber PRINT MyNumber+100
... and run that.
You should get "Hello", and then a new line with a "?" on it.
Type a number. Press enter.
You should see the result of adding 100 to whatever number you typed before.
Not the world's most useful program! But it illustrates the use of a variable... in this case "MyNumber".
As soon as you use a variable, as we did with "INPUT MyNumber", the variable is created.
You can give it almost any name. But it is best to start with a letter, not use anything except letters and digits (0-9), and to keep it short. There are more features to learn about, but that will do for now.
Variables can hold numbers or "strings". A string is one or more letters, digits, or punctuation marks.
Examples of strings....
Fred
This, my friend, is another string ! ! % ^ ! !
This... 1234... is a string with digits.
If you want to use a variable for strings, put a $ on the end of the name. We'll see that in action in a moment.
If you want to do arithmetic with what is in a variable, do NOT put a $ on the end of the name.
Have things been going a bit slowly? That's about to change...
Revise the program. Make it...
PRINT "Hello. What is your name"; INPUT MyName$ PRINT "Please enter a number... "; INPUT MyNumber PRINT "I'm glad to tell you,"; PRINT MyName$;", that 52 times that is "; PRINT MyNumber*52 PRINT
Run that. If it doesn't work, put REM (for remark) in front of some of the lines. It will "hide" the line. Run the program again. Works now? The problem must be in one of the remmed out lines! De-rem one, find your mistake, repeat.
Notice the gap I put into the program between the 4th and 5th lines. The "only" thing it does is make it easier for us humans to read the program. It now has "two parts". A "Gather information" part, and a "Use the information" part.
But making your code easy to read is IMPORTANT.
(Don't leave the final "PRINT" out. But don't worry about why it is there!)
Insert a new line saying "REPEAT" just after the existing "INPUT MyName$".
Don't be alarmed when the indenting changes, and don't fight that.
Add a new line with "UNTIL FALSE" at the end...
...and run it again.
You can no longer use QUIT to shut the window showing what the program does. But if you needed a "52 times" calculator, surely you'd want to do more than one number? (You close the window with the little "x" in the upper right.
When that's working okay, get fancy... replace the existing "UNTIL" with the following, and add the other statements...
UNTIL MyNumber=999 PRINT "GoodBye" PRINT WAIT (300) QUIT
... and try to figure out what that was meant to add. Does it?
(If you say WAIT (300), the computer stops for 3 seconds before it goes on to the next statement.)
Remember how it felt we were going too slowly... at first?
Happier now?
Change the "UNTIL FALSE" and make it "UNTIL MyNumber=0"
And add "QUIT" after the UNTIL line.
Think about it... we've learned how to use the IDE. We've made a start towards understanding....
PRINT INPUT variables REM REPEAT... UNTIL WAIT (x) QUIT
I've also used "statement" and "IDE" a few times.
A "statement" is something like PRINT "Hello". It is comparable to a sentence, in the sense we use that when talking about writing well in English. (And most other languages, as far as I am aware!)
"IDE" stands for "Integrated Development Environment".
An IDE helps a programmer create software by providing an editor in which to write the sourcecode, and that editor is "joined up" well to the things that turn the sourcecode into what the computer will need, if it it to do what the sourcecode specifies.
IDE's also usually offer tools to help with debugging.
The editor in an IDE will usually offer syntax highlighting.
Some IDEs... including the one we are using to learn BASIC allow you to run software meant for a completely different typecomputer than the one the IDE is running on. So, besides the one we'll be using, there are IDEs running under Windows which let you create software which will be used on an Android.
Please get in touch if you discover flaws in this page. Please mention the page's URL. (wywtk.com/prgm/bas/bas0.htm).
If you found this of interest, please mention in forums, give it a Facebook "like", Google "Plus", or whatever. If you want more of this stuff, help!? There's not much point in me writing these things, if no one feels they are of any use.
|
Unlike the clever Google search engine, this one merely looks for the words you type, so....
* Spell them properly.
* Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....
Please also note that I have four other sites, and that this search will not include them. They have their own search buttons.
My SheepdogSoftware.co.uk site, where you'll find my main homepage. It has links for other areas, such as education, programming, investing.
Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org.
Why is there a script or hidden graphic on this page? I have my web-traffic monitored for me by eXTReMe tracker. They offer a free tracker. If you want to try one, check out their site. Neither my webpages nor my programs incorporate spyware, but if the page has Google ads, they also involve scripts. Why do I mention the script? Be sure you know all you need to about spyware.
....... P a g e . . . E n d s .....