Flow charts are diagrammatic ways to represent a list of actions that happen and the order they happen in.
To introduce the idea we will look at simple flow charts that use just 3 different shapes.
Ovals are used to show the beginning and end.
Rectangles are used to state actions.
Diamonds are used to indicate decisions that need to be made. You can think of these as questions.
So to multiply 7 by 5 we can follow the flow chart:
What is the output of this algorithm if the input is 4?
A linear sequence is a flow chart that moves from beginning to end in one straight line. There are no decisions, just a sequence of steps to undertake.
Whenever we need to make a decision our flow chart branches out. Check out this flow chart.
This flow chart has a decision, remember that the decisions are in the diamonds. The answer to a decision can be yes/no, or true/false etc. In this case, our TRUE answer resulted in an action and the FALSE answer resulted in the Stop command.
We could introduce an action after the no answer if we wanted to. What sort of actions could that be? What actions suit this context?
Because the decision has a yes or no answer, this creates what we call a branch in our flow chart.
What is the output of this algorithm if the input is A=2 and B=5?
If a decision has a yes or no answer, this creates a branch in our flow chart.
In some flow charts we might want to PRINT, the number or answer. This could be on a computer screen, on a piece of paper or just to have the person write the number down in their book.
Sometimes we set a word to mean "whatever number we chose". For example, I could say SET \text{NUMBER}=5, and it would mean that the word number is always understood to be the value of 5. At least until it is set as another value.
The final thing we will look at in this section is a loop. Just like when you make a loop out of wire and you can trace your finger around and around the loop, so too loops in algorithms mean we can go around and around, until the code tells us to stop.
Follow this flow chart through from the START and determine what it is trying to achieve.
What did you get after following this flow chart? The statement "SET number = 1" sets the value of number to be 1. But then the statement "SET number = number +1" increases the value of number by 1.
You would have PRINTed (written down) the numbers from 1 up to 10 on your page, one at a time as you were working through the loop.
How could you change this flow chart to just print the numbers 1-5, or the numbers 5-10? What could we do/change or add to print the numbers 2,4,6,8,10 or the 5 times tables up to 50.
Which of the following flowcharts contain a loop?
SET is used to make a letter or word equal to a particular value.
PRINT is used to write an output either on the computer screen or on paper.
Loops in algorithms and flow charts mean that we repeat some action until a condition is satisfied and then we stop. They actually look like a loop in a flow chart.