YaBasic: The beginners choice
By Michael "Cup of Squirrels" Garwood
So you know how it is, you have some kind of sudden fascination with computers, and want to learn how to program. This could be for a number of reasons: You could be a middle aged man who wants to get with the times, you could be a teen who has no life (Much like me :/) or your just a computer nerd. Whatever your reasons, I'm here to introduce you to the wonderful world of programming!
Right then! How do I get started?
Trust me, programming isnt something you can do overnight, it can take anything between 18 months to 2-3 years. I still havn't reached "programmer" status and im sure a large percentage of people on this forum havn't. Thats the wonderful thing about programming: you cant learn it by yourself, you need support and advice from other people, like here! Anyway, back to the question how do you get started? Easy! First, make sure you have these items ;D
- A computer or laptop
It doesnt matter on its speed. I have a computer with top of the range hardware, and an old laptop which can barely run anything! As long as it works, use it!
- A working operating system
This is where the programming community is divided i'm afraid. You have three choices: Windows, Linux (or another Unix system) or Mac. Personally I use Windows, but choose what you want. If your a beginner, i'd stick with Windows becuase Linux is a SOB to install. A lot of people say Linux is the best for progamming, but imo Windows and Linux are the same really. As for Mac, im not really sure. There are languages to use for it, but you may hit a few walls. Dont be discouraged though!
- A brain
- A spare weekend
To learn this very simple language, you're going to need to set aside a weekend.
Yabasic stands for Yet Another BASIC (and BASIC stands for something else, but I cant remember and cba to look it up ;D). You can obtain it here.
Trust me, this is THE most important tool ANY programmer needs. You use it to write your programs. Although, when you start to get into programming you will find notepad is not useful whatsoever. I personally use metapad formany reasons: it will display what line number you are on (VERY useful if you are sorting out an error) also you can run your programming without having to close and save metapad, then double click on your program: you just select the run command from the menu!
Right, so you've got all these things ready and raring to go, and then, something hits you: why use this tutorial? I mean, let me be honest, I am only 13 but for the love of god dont judge me by my age, I am intelligent and have been into computers for about 4 years now, learning HTML (web page programming) at the age of 10. Trust me, I know what im doing. The reason this tutorial is special is that I will do my best to not use any fancy words. That is what really naffs me off about newbie tutorials: they expect you to have all this computer volcabulary. Eventually i'm afraid, you will need to learn what all these things mean, but I'll leave that to a pro, im just here to introduce you to programming with simple words :)
Ok, Yabasic is installed, now what?
Right, you will see the following files in your yabasic folder:
- readme.txt - just a simple file telling you that you just downloaded yabasic (if you didnt already know that) and some legal mumbo jumbo (enjoy reading if your a lawyer!)
- setup.exe - This is the install file. Use if you need to reinstall or uninstall (remove) yabasic
- yabasic.exe - this is the program used to run your programs :/ you can write your programs in it, but you are unable to save
- Yabasic.htm - the manual for yabasic
- yabdemo.yab - A quick demo for showing you what yabasic can do
- yabico.ico - the icon file so you can have those cute blocks for your yabasic programs ^^
- lib - lib is a folder where you put all your programs you've written
Ok, during this tutorial I will be showing how the programs are written and run by using boxes. Now I DID promise simple words, but here im afraid and im gonna have to use "complex" words: input and output.
Input is the program you write, it is also a command you use in writing your progs for telling the program information (i.e what is your name?)
Output is that the program shows when you run it
Also in someof the codes I will use # and // to add comments. A comment is just something for someone else (or yourself for that matter) to know what the line is about. You dont HAVE to add comments. The special thing about comments is they are ignored by YaBasic, so they do not count as code, simply comments :D
Anyway lets get started!
The most simple command: print
Printis simply a command used to show....words. Later I will show you how to display slightly more complicated things but for now, lets keep simple ;)
Now, for some reason, it is traditional to introduce a language with "Hello world!" so lets begin!
Right click in your lib folder and select "new yabasic program"andname it to whatever you want (i.e hello.yab) please remember you MUST have .yab at the end of your file or it will not work!
Right click it, and select "edit"
Inside your text editor, put this in:
# hello.yab # The famous Hello world program! Print "Hello world!"
Oh by the way it doesnt matter if print is Print or print, they mean the same thing as with many commands
Right save and closeand double click your program to run it. Yabasic.exe will start and show this:
Hello world! ---Program done, press RETURN---
Pressing return (or enter, whatever you call it!) will close yabasic. Cool huh? Lets move onto some slightly more complicated things!
Input is a command that displays a question (or whatever you want!) and then you can put in what you want with your keyboard :)
Here is an example:
# name.yab # Simple program to show input and how to display it Input "What is your name? " name$ Print "Hello ", name$," you are using a yabsic program!" So when you run your program: [b]Output[/b] [code] What is your name? Mike Hello Mike you are using a yabasic program! ---Program done, press RETURN---
Notice how we need to add spaces for the colons when writing the print bit. This is simply logic otherwise you would end up with
HelloMikeyou are using a yabasic program!
The same with the Input, but this is not as essential.
The if command is used for doing different things depending on what you input and other things like that :D
For now we are going to stick with simply using Input for the if command. Eventually you will know how to use the if command for other uses but im not gonna confuse you :)
Right lets get started. We will use a simple password program. I am going to introduce an extra command here: repeat
Repeat is pretty self explanitory command, but its use is slightly more complicated then you would imagine. Lets look at our next prgram for a clearer view :)
# password.yab # Password program using repeat and if answer$ = "42" Input "What is the password? " pass$ If (pass$ = answer$) Then Print "You got it right! Have a cookie ^^" End Endif If (pass$ <> answer$) Then Repeat Input "Incorrect password, please try again: " pass$ Until (pass$ = answer$) Print "You got it right! Have a cookie ^^" Endif
What is the password? 98 Incorrect password, please try again: 54 Incorrect password, please try again: 42 You got it right! Have a cookie ^^ ---Program done, press RETURN---
Ok, lets go through this program step-by-step:
First, we "declare" to the program that answer$ is 42
Then, we have a basic input asking for the password
Then an if command comes in. This tells the progran that if you enter "42" as the password, it matches it with the answer (answer$) and ends the program with a cute little message :). Then, we have a second if command, telling the program that if the user doesnt enter 42 for the password then it will repeat the incorrect message until the user finally enters 42.
Notice how I put and "endif" at the end of the if parts. This is to show that this if comnmand has finished and MUST be used whenever you make an if command.
In my opinion, this is the most boring part of programming, and the most useless, but it seems neccesary and im sure it will come in handy when we all get onto
C and C++. For now, I will show you how to print 1-10 using two different methods:
How to make a loop with while and wend
a = 0 max_num = 10 While (a <= max_num) Print a; a = a + 1 Wend
0 1 2 3 4 5 6 7 8 9 10
And here is how you make a loop with for and next:
For a = 0 TO 10 Print a; Next a
0 1 2 3 4 5 6 7 8 9 10
Ok, im not going to bother explaining these loops because like I said, you dont need them at this level in my opinion
Thats it? Meh, that was easy...
Well, thats the point of yabasic. It simply teaches the basic points of programming and some simple commands
that many other languages use, but they may differ depending on the language.
There are a few more commands for Yabasic that can be found in the yabasic manual but you needn't worry about them unless you
really want to get into yabasic. For now, experiment! Dont just leap onto the next beginner language! Make sure you have mastered
the basics of yabasic until you take the next big scary step into the world of programming ;)
Thanks for reading!
If you need to conact me for any reason (you hated/loved my tutorial, you need some help, I screwed up somewhere, you wanna say "you r0x0r my b0x0r cup of squirrels!") then you can e-mail or msn me on email@example.com or if you know how to use IRC i am known under CupOfSquirrels and/or Cup|Craptop and I usually hang around #bryns. Dont worry, im not a snob with auto-replies! Im a real person and im more than happy to help! For now, enjoy!