1,105,594 Community Members

YaBasic: The beginners choice

Member Avatar
Cup of Squirrel
Junior Poster
131 posts since Oct 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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
  • Fingers
  • A spare weekend
    To learn this very simple language, you're going to need to set aside a weekend.
  • YaBASIC
    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.
  • notepad
    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:

Input

# 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:

Output

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
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:
Input

# 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.

If!
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 :)

Input

# 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

Output

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.

loops
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

Input

a = 0
max_num = 10
While (a <= max_num)
Print a;
a = a + 1
Wend

Output

0 1 2 3 4 5 6 7 8 9 10

And here is how you make a loop with for and next:

Input

For a = 0 TO 10
Print a;
Next a

Output

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 cupofsquirrels@hotmail.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!

Member Avatar
Nuez_Jr
Newbie Poster
18 posts since Oct 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Code Style
---------------

Comments are useful for telling people WTF this code is supposed to do, but there's another aspect to readability - formatting!

Most languages allow a programmer to write code that is perfectly legal according to the syntax rules of the language, but is nonetheless a snarled and unreadable mess. For example, C syntax doesn't care how much whitespace goes between statements, parts of statements, etc...just so long as the names have at least one space, it's generally still correct code. But! Reading code that doesn't follow consistent formatting rules tends to be difficult.

A few guidelines to get started:

-consistent naming: if you're going to name you variables in UPPERCASE, then keep them in UPPERCASE. If you're going to make long_descriptive_variable_names, then stick to the long_descriptive_variable_names style.

-newlines: use vertical grouping and/or separation to show the logical steps in your code. A quick-and-dirty criterion for this is to describe to yourself what it is the code is supposed to do, and group all the lines that make up the implementation in code (be it C++, Ada, Ruby, or whatever else) of each sentence in English (or Spanish, or French, or Ukranian...). Don't be afraid to put a lot of blank lines in if there's a chance it will make it easier to see what's going on.

-indentation: This one is pretty much universal - If you write a control statement of some kind, indent the code inside it. For-loops, while-loops, if statements, case statements, try/catch blocks...if it has starting and ending portions (eg, IF...ENDIF), then the code between them should be distinguished from the code outside. Different people will tell you different numbers for how many spaces to indent each level, and it's largely immaterial how many you choose.

-comments: Comments fill two main roles: Documentation, and Clarification. The simplest case of using comments is to describe what you just did or are just about to do. My own practise is to comment wherever I can expect to need an explanation when I come back two months later and have no idea what I was thinking. As for documentation, if you're writing code for someone else, like a teacher or a boss or teammates or a client, they'll likely want to be able to understand your code. Documentation comments are typically a large block of comments at the top of each file listing what's in each file, and also descriptions of each functional module - procedures (aka subroutines), functions, classes, etc.

...


But over top of all these suggestions is one overriding concern: CONSISTENCY!
You can take twelve source files that are all part of the same project, pick twelve different styles of formatting, all very nice and logical, and apply one style to each file....and out of every ten other programmers you show those twelve files to, at least nine of them will be p****'d off at the inconsistent formatting.
Every company typically has their own set of code-style guidelines, and the larger the company, the more pedantic the rules will be. For example, the rule that says every opening paren '(' must be followed by a single space, and every closing paren ')' is to be preceeded by a single space. Personally, I think that looks ugly, but were I to work for the company that follows that particular convention, I would adhere to it, because that's what the other coders I'm working with will expect to see. It's pointless to waste time reading code that looks funny because the style is unfamiliar, when what we really want to be doing is thinking about the ideas, algorithms, and structures that are involved.
And if you do find yourself in a position of being required to conform to a set of style rules, I think you'll find that what initially may seem ugly or just strange, will fade into the background once you get used to seeing it.

Member Avatar
Cup of Squirrel
Junior Poster
131 posts since Oct 2004
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok i'll take that into account. I only wrote this really to play my part in the community, seeing as i've asked so many annoying questions.

Like I said at the beginning of the tutorial I didn't want to use advanced programming volcabulary because the yabasic site tutorial confused me, so I wanted to write a simpler version 0_o

But thanks for the advice, i've never really been good with communicating :<

Member Avatar
thecompans
Newbie Poster
1 post since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

can you please make a tut about the more advanced stuff? i really like the way you made that tut but i want to get into more advanced stuff. ty!:)

Member Avatar
Makcarov
Newbie Poster
12 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I tried it all the basics but I didn't work at all.

Member Avatar
Makcarov
Newbie Poster
12 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I mean the outputs didn't work or it didn't appeared the same as in the tutorial.

Member Avatar
gaurav_15
Newbie Poster
1 post since Mar 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ur article was very helpfull for me i want to learn more and also have some questions i can ask if i m able to chat with u .

You
Post:
Start New Discussion
Tags Related to this Article