Sequencing
When writing a computer program it is important to ensure that each line of code is in the correct order.
Imagine making a cup of tea and putting the cold water into the cup before it has boiled and then adding the milk and then a tea bag. Each stage is an individual instruction but they are out of sequence and therefore result in the incorrect outcome, a cold cup of tea.
Sequencing applies when creating your program, for example, a picture has to be taken with the camera before it can be saved to a file. Otherwise the program would produce an error and fail. You will use sequencing in all the projects.
Variables
Objects, like people have a name that can be used to identify or refer to them, for example the make of a car, the name of your child or the name of the company that provides your Gas.
In programming a variable is a label or name used to refer to value, data, or text that is stored. Although the label stays the same the value it stores can vary, it can change. Consider a variable called ‘gas company’ this contains the name of the company supplying your gas, but, you can switch company and therefore the name stored could also change.
In a computer game a variable is used to store the player's current score. As you progress in the game your score changes and goes up or down. Each time it changes, the new value needs to be stored in the the variable. All the projects will use variables and teach you more about them.
Selection
Selection is also used with the options you are presented with at a cash machine. For example 'Do you want to see your balance?', How much do you want to withdraw? Do you want another service? The program then responds in an appropriate way dependent on the choice that you make.
Computers execute instructions in the order they're written. Sometimes, you won't always want the computer to do exactly the same thing each time. You can tell the computer to select what to do based on, say, the value stored in a variable.
For example at the end of a game you may be asked if you want to play again, if you answer Yes the game begins if you answer No then the program quits. If a player’s score is higher that the current high score, then set the player's score to be the new high score and ask for their name, else do nothing.
Data Types
Computers have their own method of storing lots of different types of data, they cannot distinguish between numbers, letters or symbols so we program it with what type of ‘data’ is being used or entered.
integer - a whole number
floating point - a decimal
text - a letter or character
boolean - a Yes or No value or True or False
This allows a program to determine the possible values for that data type and the operations that can be done on values of that type. If you win a game it may ask you for your player’s name, this is usually a ‘text’ data type which tells the program to accept letters between a and z. When asked if ‘you want save you work’ makes use of a Boolean value, yes or no.
You will use data types in project ..
Functions
If you listed all the stages involved in brushing your teeth you could probably write a list of 30 plus instructions. Pick up the toothpaste, hold the lid, unscrew the lid and so on. It would become very tedious and time consuming if you had to tell your child all these instructions every time you wanted them to brush their teeth. Instead you say ‘brush your teeth. This is a function, a phrase that holds all the instructions to brush your teeth.
In programming functions are used to save time repeating longer lines of code. In a computer game when you press the run button your player will run. This takes several lines of code to perform the movement. Within the program is a function called run.
Within the ‘run’ function will be stored the lines of code which enable the program to control player to run.p. A function means you can use a few words to ‘call’ a much longer set of code anywhere in the program. Functions are used in all the programs.
Repetition
In a program you will want a particular action or event to keep happening or repeating, this is called a loop.
A loop is a sequence of instructions repeated until until a certain condition is reached. A player continues to play the game until their lives reach zero, then the loop stops and the game ends.
The most commonly used loops are WHILE and FOR loops. A WHILE loop repeats while a certain condition is met for example WHILE you are pressing the jump button make the player jump. A FOR loop repeats a specific set of instructions for a set number of times. If you had a 4 player game and the game ended a FOR loop could be used to calculate the scores and rank the players. The FOR loop would run four times since there are 4 players
When writing a computer program it is important to ensure that each line of code is in the correct order.
Imagine making a cup of tea and putting the cold water into the cup before it has boiled and then adding the milk and then a tea bag. Each stage is an individual instruction but they are out of sequence and therefore result in the incorrect outcome, a cold cup of tea.
Sequencing applies when creating your program, for example, a picture has to be taken with the camera before it can be saved to a file. Otherwise the program would produce an error and fail. You will use sequencing in all the projects.
Variables
Objects, like people have a name that can be used to identify or refer to them, for example the make of a car, the name of your child or the name of the company that provides your Gas.
In programming a variable is a label or name used to refer to value, data, or text that is stored. Although the label stays the same the value it stores can vary, it can change. Consider a variable called ‘gas company’ this contains the name of the company supplying your gas, but, you can switch company and therefore the name stored could also change.
In a computer game a variable is used to store the player's current score. As you progress in the game your score changes and goes up or down. Each time it changes, the new value needs to be stored in the the variable. All the projects will use variables and teach you more about them.
Selection
Selection is also used with the options you are presented with at a cash machine. For example 'Do you want to see your balance?', How much do you want to withdraw? Do you want another service? The program then responds in an appropriate way dependent on the choice that you make.
Computers execute instructions in the order they're written. Sometimes, you won't always want the computer to do exactly the same thing each time. You can tell the computer to select what to do based on, say, the value stored in a variable.
For example at the end of a game you may be asked if you want to play again, if you answer Yes the game begins if you answer No then the program quits. If a player’s score is higher that the current high score, then set the player's score to be the new high score and ask for their name, else do nothing.
Data Types
Computers have their own method of storing lots of different types of data, they cannot distinguish between numbers, letters or symbols so we program it with what type of ‘data’ is being used or entered.
integer - a whole number
floating point - a decimal
text - a letter or character
boolean - a Yes or No value or True or False
This allows a program to determine the possible values for that data type and the operations that can be done on values of that type. If you win a game it may ask you for your player’s name, this is usually a ‘text’ data type which tells the program to accept letters between a and z. When asked if ‘you want save you work’ makes use of a Boolean value, yes or no.
You will use data types in project ..
Functions
If you listed all the stages involved in brushing your teeth you could probably write a list of 30 plus instructions. Pick up the toothpaste, hold the lid, unscrew the lid and so on. It would become very tedious and time consuming if you had to tell your child all these instructions every time you wanted them to brush their teeth. Instead you say ‘brush your teeth. This is a function, a phrase that holds all the instructions to brush your teeth.
In programming functions are used to save time repeating longer lines of code. In a computer game when you press the run button your player will run. This takes several lines of code to perform the movement. Within the program is a function called run.
Within the ‘run’ function will be stored the lines of code which enable the program to control player to run.p. A function means you can use a few words to ‘call’ a much longer set of code anywhere in the program. Functions are used in all the programs.
Repetition
In a program you will want a particular action or event to keep happening or repeating, this is called a loop.
A loop is a sequence of instructions repeated until until a certain condition is reached. A player continues to play the game until their lives reach zero, then the loop stops and the game ends.
The most commonly used loops are WHILE and FOR loops. A WHILE loop repeats while a certain condition is met for example WHILE you are pressing the jump button make the player jump. A FOR loop repeats a specific set of instructions for a set number of times. If you had a 4 player game and the game ended a FOR loop could be used to calculate the scores and rank the players. The FOR loop would run four times since there are 4 players