2 minute read

DRAFT

Now try this!

You will need: paper and a pen

Work in pairs.

Partner A: Draw a simple picture (for example, a house, a fish, a flower…). Don’t show it to your partner! Now give instructions to your partner to draw the same picture, but don’t tell them what it is.

Partner B: Follow your partner’s instructions to draw the picture. Can you guess what it is? Are the two pictures the same?

Swap roles and try the activity again.

Draw an oval. Inside the oval, draw a smaller circle at the end.

Talk about the activity with your partner. Think about these questions.

1 What was the easiest part for you?

2 What was the most difficult part?

3 Which instructions were the best?

4 Did you have to change anything? If so, what?

Follow and understand repeating algorithms

An algorithm is a set of instructions. When we follow the instructions carefully, they help us complete a task successfully. Algorithms can be written instructions, spoken instructions, or even diagrams.

Programmers use algorithms to plan their programs and identify possible problems. We use algorithms in our everyday life, for example when we use:

• instructions to play a game

Give each player five cards.

Linear algorithms

Linear algorithms contain instructions that we must follow in the correct order, one after the other. When you get to the end of the instructions, the algorithm stops.

This is an example of a linear algorithm that we can use to shop for food.

1 Walk to the shop.

2 Choose items.

3 Pay for shopping.

4 Walk home.

This linear algorithm can also be shown as a diagram:

These algorithms look very different, but they both give the same instructions and solve the same problem.

Algorithms can be presented as written instructions or as diagrams, depending on what is most helpful for the user. For example, a diagram is often easier to follow when building a model using toy building bricks. But to cook a meal, the written instructions in a recipe are more helpful.

1.1 Repeating algorithms

Questions

1 What is a linear algorithm?

2 Why is it important to check each instruction in an algorithm is in the correct order?

3 Why can it be better to present an algorithm as a diagram sometimes?

Loops

Sometimes algorithms contain instructions that need to be repeated. This is known as a loop.

Look at the diagram below. It shows an algorithm that uses a loop. Use your finger to trace the direction that you take through the algorithm as you follow the instructions.

What is this algorithm for?

Questions

Think about how the sun rises and the sun sets. Discuss the answers to the following questions with a partner.

4 Does this only happen once and then stop?

5 What is being repeated?

6 When would the loop stop?

The instructions in the sun rises, sun sets algorithm repeat and never stop. These types of instructions are known as a forever loop. In a forever loop, the cycle keeps repeating forever and does not stop.

This algorithm in written instructions looks like this:

1 Sun rises.

2 Sun sets.

3 Sun rises.

4 Sun sets.

5 …

It’s impossible to use written instructions for a forever loop –they go on forever!

A much faster and easier algorithm would be:

1 REPEAT FOREVER.

2 Sun rises.

3 Sun sets.

The words REPEAT FOREVER show that the instructions indented below the REPEAT FOREVER instruction continue to repeat.

The algorithm will repeat forever. Another name for a forever loop is an indefinite loop.

Unplugged activity 1

Work in pairs to follow this algorithm that uses an indefinite loop. Repeat the actions in this indefinite loop until your teacher tells you to stop.

1.1 Repeating algorithms

This algorithm could go on forever and make the class very, very tired! But we only need to repeat it until the teacher says ‘Stop’.

1 REPEAT FOREVER.

2 Take 1 step to the right.

3 Clap your hands.

4 Take one step to the left.

5 High-5 with a partner.

6 Say ‘indefinite loop’.

This article is from: