Let's start looking at how to program for ourselves. The first thing we need to do is to be able to store the results of calculations. Let's think about a program which add two numbers together. Below is the code for this.

Answer = 1 + 2

Here we are adding 1 to 2. Clearly the answer is 3, but what do we do with the answer? We must place this answer somewhere so we can do something with it later. We want to put it into a variable.

Lets look at this simple statement in more detail. Before the command above is run, the variable Answer, has a unknown value. Even if we know what value answer has it really does not matter as the code will overwrite the current value of answer. The equals sign in this case does not mean equal to. What it means is assigning to. So reading the above line out load I would say

"I am assigning the value of 3 to the variable Answer"

Rather than

"Answer is now equal to 3"

The assignment operator, =, is one which you will use all of the time and one that can get very confusing.

The variable Answer is stored somewhere in memory. That memory is then assigned the new value of 3 due to the code. This value can be recalled at anytime in order to use it.

Consider the next program

A = 3 * 5 
B = 5 * 5 
Answer = B - A 


The third line of the program is using the values of the variables A and B. The following diagram demonstrates this.

The first line assigns the value 15 into the variable A. The second line assigns the value 25 into the variable B. Finally the third line gets the value 25 from B and subtracts that value by 15; which is retrieved from the variable A.


Although we could do this on one line, we are showing how variables can be used to recall information. This is a very important part of programming.