GCSE Link: 2.01 (Variables)

This page contains only GCSE content. There is nothing new in this topic at A Level, so the most important parts have been included below.

Variables are named references to locations in memory for temporarily storing data while a program is running.

Each variable or constant should have a meaningful and unique identifier (name). Identifiers can't be reserved keywords (like if, for or while), or start with numbers.

A constant is a special type of variable whose value does not change as the program runs.

Constant identifiers are usually written in CAPITALS.
 

Sequence is just a matter of writing of writing down the steps in the correct order.

Selection allows you to choose between multiple options.

Example 1 shows how an IF statement can be used in C#.

Example 1
int age = Console.ReadLine();
if (age >= 18) {
  Console.WriteLine("OK");
} else {
  Console.WriteLine("Too young");
}

Iteration means looping. There are three different types of loops in pseudo-code.

Example 2 shows an algorithm containing a for loop.

Example 2
int total = 0;
for (int i = 0; i < 5; i++) {
int num = Console.ReadLine();
  total += num;
}
Console.WriteLine(total);



What does the code in Example 2 do?

The algorithm asks the user for five numbers and outputs their sum.