A-level Computing 2009/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Fundamentals of Programming/The Role of Variables



 As we have seen variables can play a very important role in creating programs and especially when executing loops. The roles of these variables can be categorised into several types:

in the above code it is easy to see the use of a fixed value and a stepper. Let's look at a more complicated example: In the above code you can see the various roles of variables in collecting together 10 inputs and adding them all together (gathering):

In the code above you can see the use of the most wanted holder to store the maximum value from an array of numbers. As you cycle through each item in the array (using the stepper c), you update the  to store the maximum value that you come across. Let's take a look at a more complex example The code above describes a single pass of bubble sort. Using the temporary variable,, we bubble the largest array value to the top of the array, by comparing the current array value  and the follower. In summary: Finally let's look at an example of a transformation, we have used lots of loops so far, but variables certainly aren't only used in loops: In the code above there are two transform variables  and.

For the above code name the role of each of the following variables:

For the above code name the variables that act as a:

The roles you see here are included in the syllabus and it is very likely that they will be examined. There are several other roles out there which aren't covered here, these include: You can find out more about them here
 * one-way flag
 * organizer
 * container
 * walker