Heaney

Soft


HeaneySoft's BASIC Tutorial
Section 1: Just the basics


Input/Output:
All programs have to interact with the user in some way or another. There are two ways of doing this: when you want information from the user, that is called an Input, and when you want to give the user information, that is called an Output. For example, lets say you have a math program that does multiplication. In order for this program to help a person, it would need at least two numbers, so you need it to ask the user for two numbers. For this we would use an input statement, which will be talked about in the next section. Then, when the program is done multiplying the numbers, you would want it to give the final answer to the user, and for that you would use an output statement, which will be talked about in the third section.

Conditional statements:
There are times in programming when you will want the program to make a decision based on information that it has stored. Lets go back to the math program for another example. Lets say we wanted the program to tell us how many digits were in the answer. We'll assume that all answers are less than 1000, so now the calculator comes to a fork in the road with three different options: one digit, two digits, or three digits. To make this fork we must use a conditional statement, and to the calculator it would look something like "If the number is less than 10, tell me it has one digit. If the number is less than 100, tell me it has two digits. If the number is anything else, tell me it has three digits." We will learn about this in the fourth section.

Loops:
In programming you always want to use as little space as possible and save time by typing less. We do this by making loops in the program. If there's ever anything that we want to do more than once, all we have to do is type it once and then loop back to it as many times as we like. Lets go back to the math program again. Pretend the computer doesn't know how to multiply, how are we going to get this to work? If the problem was 3 times 4, all we would have to do is start at zero and add 4, then loop it back until it has done this three times. So the computer would enter the loop and it knows two things: loop 3 times, add 4 each time. First loop: 4, second loop:8, third loop: 12, done. Loops and similar commands will be the last of the fundamentals, in the fifth section.

Variables:
Whenever a program inputs or manipulates information, it needs to save it some how for later reference. For this we use the memory provided by the calculator. Usually when someone is learning how to program they use the calculator's most basic form of memory: variables. You can find a variable by pressing the alpha button followed by any of the twenty-six green letters. Variables are just blocks of memory that hold information, in this case, numbers. In order to keep track of these blocks of memory they are given names, like A, B, C, etc. So I'm going to use the math program for one last example. This program needs to use variables for two reasons. First, it inputs information from the user, and second, it manipulates the information inside the program. So, we want to get values from the user, lets call those values A and B, that's what they would be stored as on the computer, we don't know what numbers they are, but this way we can keep track of them. Now we have A and B, we want to put A in a loop where we add it B times, and we will put the answer in a variable called C. When this is done, we tell the program to output the information however we want. You will see an example of this in the next section, with inputs.

Knowing these four things, we can outline a structure for any kind of program we want, now we start learning how to turn it from an outline to an actual program.

Intro | Index | Section 2

Comments, Questions, or Ideas: Click Here | Home

Copyright © 2004 HeaneySoft