Loading...
Welcome to this lesson, which is called Patterns and Repeats, and it's from the unit Repetition in Programmes.
I'm really pleased you've joined me for this lesson and I look forward to learning with you today.
The outcome of this lesson is that you will be able to describe repetition.
This lesson has three keywords.
First we have pattern.
A pattern is a design or sequence that repeats.
Then we have repeat, and repeat is something that happens multiple times.
And then we have count-controlled loops.
A count-controlled loop is a chunk of code that repeatedly runs a section of a programme a certain number of times.
So our three key words are pattern, repeat, and count-controlled loop.
This lesson has two learning cycles.
First of all, you're going to look at how to write commands to draw a shape, and then later in the lesson you will describe count-controlled loops.
So let's get started with the first learning cycle.
A pattern is a design or sequence that repeats.
Which flag will come next in this pattern? Which part is repeated, and how many times is it repeated? The striped flag is next.
When you add the striped flag, the flags repeat in this order, black, white, spotted, striped.
This pattern repeats twice.
There's our first repeat, and there's the second repeat of the pattern.
Look at the pattern of the black keys on this piano keyboard.
Which part is repeated and how many times is it repeated? So the pattern of the black keys is two, then three, then two, then three, then two.
So there's two, then three, then two, then three, then two.
The next group of black keys will be three.
The pattern of two, three will be repeated three times.
Now it's time for a question.
Which of these is an example of repetition? Is it A, making up a story.
B, clapping five times.
Or C, drawing a different shape each time? Well done.
The answer is B, clapping five times.
So this is an example of a single clap being repeated five times.
So here's a picture of somebody brushing their teeth.
Which action is being repeated here? Many actions are repeated when you brush your teeth, including brush your front teeth up and down, brush left lower side forwards and backwards, brush left upper side forwards and backwards, brush right lower side forwards and backwards, brush right upper side, forwards and backwards.
Algorithms can be presented in different ways.
Writing instructions or a list is one way.
So Aisha has put together some instructions for brushing your teeth.
Number one, put toothpaste on toothbrush.
Number two, put the toothbrush in your mouth.
Number three, brush front teeth up and down.
And Alex asks, "How many times is this step repeated?" Aisha says, "I'd say at least 10 times." So Alex says, "We can record that in our algorithm by using a symbol." "Like writing 10 times, or times 10," says Asia.
And there we have it.
So number three now, brush front teeth up and down 10 times.
Here's Aisha's instructions for brushing your teeth.
Number one, put toothpaste on toothbrush.
Number two, put toothbrush in mouth.
Number three, brush front teeth up and down.
Four, brush left lower side forward and backwards.
Five, brush left, upper side forwards and backwards.
Six, brush right lower side forward and backwards.
Seven, brush right upper side forward and backwards.
Eight, rinse your mouth.
Aisha says, "When something repeats, it happens lots of times." So now Aisha can add in how many times these actions are repeated.
So step three is repeated 10 times, step four 20 times, step five 20 times, step six 20 times, and step seven 20 times.
Let's have a look at a true or false question.
Repetition is only about numbers.
Is that true or false? So repetition is only about numbers, true or false? Well done.
The answer is false.
Can you explain why? So, repetition means any repeated action, not just counting.
An example of this is brushing both sides of your teeth.
Logo is a text-based programming language.
You use Logo to type commands that are then drawn on screen.
These Logo commands can be used to programme the turtle to create shapes.
You can use fd for forwards, bk for backwards, rt for right turn, lt for left turn, cs for clear screen, pu for pen up, pd for pen down, and home to return the turtle to the start position.
In this lesson, you will design an algorithm for drawing a square.
You can choose to design your algorithm in two different ways.
You can write your algorithm as a list of instructions.
So the first two instructions could be, go forward 100 steps, turn right 90 degrees.
Or you could draw your algorithm as an annotated diagram.
So let's have a look at the first couple of steps so that way, so we can have the start position labelled with the arrow pointing upwards.
You would then say 100 step forwards and annotate your drawing with which part of the square that is.
Right turn 90, and so on.
Create your algorithm for drawing a square.
Decide whether to create your algorithm as a labelled diagram or as a list of instructions.
Here's the steps to follow.
Number one, mark the start position and direction.
Two, include the directions, and their lengths, and any turns or degrees needed.
And three, number the instructions.
To create your algorithm as a list of instructions, it could look like this.
One, go forward 100 steps.
Two, turn right 90 degrees.
Three, go forward 100 steps.
Four, turn right 90 degrees.
Five, go forward 100 steps.
Six, turn right 90 degrees.
Seven, go forward 100 steps.
Eight, turn right 90 degrees.
And as an annotated drawing, it could look like this.
So the start position in the bottom left of the square labelled with the arrow's pointing up.
Number one, 100 steps forward.
Two, right turn 90 degrees.
Three, 100 steps forward.
Four, right turn 90 degrees.
Five, 100 steps forward.
Six, right turn 90 degrees.
Seven, 100 steps forward.
Eight, right turn 90 degrees.
Next, use your algorithm to programme a square in Logo.
These commands will help you.
So first of all, we've got fd, space, and then XX.
And in place of XX you'll put the number of steps you want the turtle to move.
Then we have bk, space, followed by the number of steps you want the turtle to move.
rt, space, 90 for right 90.
So to turn right 90 degrees.
lt space 90 for left 90.
So turn left by 90 degrees.
And cs to clear the screen.
So here's what this programme will look like in Logo for a square.
We have fd, space, 100.
rt, space, 90.
fd, space, 100.
rt, space, 90.
fd, space, 100.
rt, space, 90.
fd, space, 100 rt, space, 90.
And that will make your turtle draw a square like you can see on the image.
So let's move on to the second learning cycle, which is to describe count-controlled loops.
So here's our programme again for drawing a square.
fd, space, 100.
rt, space, 90.
fd, space, 100.
rt, space, 90.
fd, space, 100.
rt, space, 90.
fd, space, 100 Now, Jacob's spotted a pattern in that programme.
What's repeated in these commands and how many times is it repeated? So here's our programme again.
The part that's repeated is fd, space, 100, rt, space, 90.
There's the part that is repeated.
And the pattern is repeated four times.
If you wrote the code as an algorithm, the instructions that are repeated could go underneath the repeat instruction.
So you could say in your algorithm, repeat four times, draw a side 100 steps long, turn 90 degrees.
One way you can show the commands that will be repeated is by moving them to the right slightly, and this is called indenting.
So you can see the two bits that have moved to the right are draw a side 100 steps long and turn 90 degrees.
They're slightly to the right indented from the repeat instruction.
When we have commands that we want to repeat a set number of times in Logo, we use the repeat command.
This is often referred to as a count-controlled loop.
Time for a question.
We have commands that we want to repeat a set number of times we use A, a programme, B, an algorithm, or C, a count-controlled loop.
Well done.
The answer is C.
We use a count-controlled loop.
This is how to use the repeat command in a count-controlled loop in Logo.
So you begin with the repeat command, then a space, and the number of times you want to repeat, then another space, and then in square brackets the command you want to repeat.
So this time we want to repeat fd, space, 100, space, rt, space, 90.
Let's break that down a bit.
So there's the command repeat.
There's how many times to repeat it.
And what you want to repeat is inside the square brackets.
Watch this animation demonstrating the commands.
So we start by typing repeat, space, 4, space, and then the command we want to repeat inside the square brackets.
So that's fd, space, 100, space rt, space, 90.
And when you execute that, you end up with your square.
So let's watch that through one more time.
We begin with the repeat command, then the number of times.
Then inside the square brackets the command we're repeating.
And when you execute that command, there's your square.
Let's fill in the blanks in these sentences.
A blank is used to repeat a set of commands a specific number of times.
In Logo the blank command helps to create patterns and shapes.
The command blank will draw a blank because it repeats blank times.
Okay, let's have a look at what goes where.
A count-controlled loop is used to repeat a set of commands a specific number of times.
In Logo the repeat command helps to create patterns and shapes.
The command repeat, space, 4, space, fd, space, 100, space, rt, space, 90, in square brackets would draw a square because it repeats four times.
Here is task B.
One, use the repeat command to programme a square.
So there's an example of the code you would need for that.
Repeat, space, 4, space, square brackets, fd 100, space, rt, space 90.
And what happens if you change the value of 100 in this programme? Test out different numbers and explain.
Okay, so using repeat, space, four, space, in square brackets ft, space, 100, space, rt, space 90, you'll get square that looks a bit like that.
What happens if you change the value of 100 in this programme? In this animation, you're going to see three lines of code run.
So first of all, repeat 4, and then in the brackets, fd 100 rt 90.
The second is the same number of repeats, but this time ft 50 rt 90.
So that draws a smaller square.
And the last one, repeat 4, and then in the brackets, fd 150, rt 90.
What do you think is gonna happen here? Well done.
We get a bigger square.
So let's watch that run through again.
So we've got three lines of code being typed in.
The only thing that's changing in each line is the value of the fd instruction, so, the length of the line.
So first one, 100.
Second value for fd is 50 to draw a smaller square.
And then finally in the third line, same instruction again, changing fd to 150, and the same turn, and we get a larger square.
So there's our three squares.
Let's have a look at a summary of this lesson.
Patterns are created by repetition.
An example of this is brushing your teeth.
Some of the steps are repeated, and you can show the repetition in an algorithm such as by writing times 10.
The repeat command in Logo makes it easier to create shapes without writing the same instruction multiple times.
And finally, a count-controlled loop repeats a set of commands a specific number of times.
Thank you for joining me and learning with me today in this lesson.
I look forward to seeing you all again soon.