Computer Languages
Elements - Variables

Variables store data for the program to work with. A variable is a name that represents a piece of data with many possible values; it can be used in the entire program (Global variable) or just in one part (Local variable).


For example, if a program has a variable called 'aboveNinety' which is to be used as a counter to evaluate a student's overall performance in examinations, while the variables 'FrenchScore', 'RussianScore' and 'SpanishScore' represent the values of their results in the individual examinations, then the program might read as follows.

ProgramExplanation
aboveNinety := 0;this sets the initial value of the counter to zero
if (FrenchScore > 90) then
    aboveNinety := aboveNinety + 1;
this changes the counter to 1
if (RussianScore > 90) then
    aboveNinety := aboveNinety + 1;
from 1 to 2
if (SpanishScore > 90) then
    aboveNinety := aboveNinety + 1;
from 2 to 3
print aboveNinety , "Language(s) above 90% ";prints "3 Language(s) above 90%"