When designing algorithms, there are many steps where decisions must be made. This decision is known as selection, and can be displayed in pseudocode or flowcharts.
A flowchartA diagram that shows a process, made up of boxes representing steps, decision, inputs and outputs. uses a diagram to explain the steps of an algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs..
Consider this simple six-step algorithm for comparing your dog’s age with your own:
ask how old the dog is in human years
multiply human years by seven to find out how old the dog is in dog years
print answer on the screen
ask how old you are
if the dog’s age in dog years is older than your age, say ‘Your dog is older than you!’
otherwise, say ‘Your dog is not older than you.’
In a flowchart, this sequence would look like this: