Programs run in sequences. Selection statements and loops are used in programs, allowing software to make decisions and repeat actions. These are called computational constructs
A variable is a location in memory used by a program to store data. It is given a name to identify it to the user and to the program. Variables are used to store data needed for programs to run.
For example, you may be writing a program to calculate the perimeter of a square, where the perimeter is calculated by multiplying the length of one side by four. This could be represented in reference language as:
SET perimeter TO sideLength * 4
You need two variables, one to store the length of one side of the square, the other to store the perimeter. For this program, you could simply use the variable names 'sideLength' and perimeter.
It is important to give variables meaningful and relevant names so that you can understand and remember their purpose. For example, you can quickly understand what a variable called 'total_sales' means, but 'ts' is not so easy to decipher.
Assigning a value to a variable
Assigning a value to a variable means putting a value into the memory location identified by the variable name. For example:
SET sideLength TO 25
This would assign the number 25 to be stored in the memory location that can be accessed by using the variable name ‘sideLength’.