What is a computer program?
We often think that computerA device that processes information by following a set of rules called a program. and computing devices are really clever.
Sometimes we think they are more intelligent than people!
They can complete lots of tasks that people can't do and do them quicker and more accurately than us. They are very good at doing more than one thing at a time.
But remember that computers can't think for themselves. They can only do what people tell them to do. We give them instructions written in a language called codeA language that a computer can understand. and we call the list of instructions a computer programA sequence of instructions written in a coding language that a computer can understand..
Computing devices have a memory, where they can store programs and other information.
We write a computer program because we want a computer or computing device to complete a task. This task might be part of a larger project, or it might be a way to solve a problem.
Computer programs and stories
When we write a story, we know it must have certain structures to make it work for the reader.
The story will have events, or things that happen in a particular order, or sequence. We call this the plot, and the sequence is usually the beginning, followed by the middle and finally the end.
The story will also usually include descriptions of the characters and the story setting.
A computer program also needs to have certain structures to make sure it can it can give the outcome the computer programmerSomeone that creates programs for a computer. intended.
Some of the important structures that make up a computer program are:
The order, or sequence of the instructions
Whether any of the instructions are repeated
Sequences - what comes first?
The sequence, or order of the instructions in any task is important.
If things are in the wrong order, the outcome of the task won't be what you wanted.
Let's look at an everyday example where the sequence of instructions is important to achieve the correct outcome - a neatly folded T-shirt!
Computers and sequences
Unlike people, computers can't tell if something is in the wrong place in a sequence. It will just carry on running the program, even if things start to go wrong.
This means we have to make sure we check our algorithms and then our program code to see if everything is in the correct sequence.
Let's look at a real-world example
In a drinks factory, the machines are all controlled by computers. The machines:
- Move the empty bottles automatically around the different sections
- Fill up the bottle
- THEN put the lids on
Can you describe what would happen if they got the computer program sequence wrong and put the lids on first?
Watch: Find out more about sequencing
This film from 成人快手 Teach gives more examples of how computers use sequencing in the real world.
Repetition - let's do it again
Repeating something, or doing the same thing more than once, can be a good way to learn or remember something new.
Imagine you were going to show an alien how to help tidy up your room. You would have to give them careful instructions.
You could say:
- Walk up to a toy on the floor
- Pick up the toy
- Put the toy in the toy cupboard
But there are 20 things to tidy up - you must have been very untidy lately.
You could just repeat the same CommandA single instruction - when part of a computer program. 20 times, but it would take a long time to tell the alien the same instructions over and over again.
Nearly as long as it would take to tidy your room!
If the alien was a robot you could use a repeatTo do something more than once. instruction like this:
Repeat 20 times:
- Walk up to a toy on the floor
- Pick up the toy
- Put the toy in the toy cupboard
The repeat command turns the instruction list into a repeat loop, where we go round and round the loop 20 times.
Repeat loops in computer programs
Computers can repeat the same task over and over again without getting bored or tired like we do.
It's one of the things that makes them so useful.
We can add REPEAT commands to our computer programs. This saves time and makes our program more efficient by using fewer lines of code.
We usually put the REPEAT command and the number of times to repeat it before the instructions themselves.
You can see the difference in the length of this program for our alien.
Activity: Quiz
Computing - Dance Mat Typing. gameComputing - Dance Mat Typing
Build and test your computing skills with different levels of touch type challenges
More on Computer science
Find out more by working through a topic
- count5 of 24
- count7 of 24
- count8 of 24