Lesson video

In progress...

Loading...

Hello, everybody.

Welcome to Computing.

My name is Mrs. Franzsen and it's really great to have you in my lesson today.

Let's get started with our learning about physical computing.

By the end of this lesson, you will be able to write a programme which contains a conditional loop.

Let's look at our keywords for today.

Our first keyword is condition.

A condition is a statement that can be either true or false.

You can see when we use the words true or false here in context of conditions that we put a capital letter for true and false.

Our next keyword is conditional loop.

A conditional loop is a chunk of code that repeatedly runs a section of the programme until a condition is met.

In the first part of the lesson, we are going to identify and create conditions.

Behind the rectangle, there are three commands for you to carry out.

As each one is shown, carry out the action.

Do two nods.

Do four touch nose.

Do three claps.

(hands clapping) What was different about the three commands that you were given? The actions were different.

The number of times that the action was done was different in each one.

What information did you need to know to carry out the commands? What action to do, how many times to do it, and when to stop.

Look at this Crumble programme.

What is similar between the commands that you were given and the count-controlled loop command block? Both have an action or set order of actions that will be carried out until the number has been reached.

You can see that here in the count-controlled loop, the value four has been circled and in our actions, the numbers have been circled as well.

A condition is a statement that can be either true or false.

Programmers can use conditions to trigger actions.

You can think of conditions as being like questions that you can answer with either yes or no.

So the true or false statement would be, "It is past 6:30 AM," and if we phrase it as a yes or no question, we would say, "Is it past 6:30 AM?" The next example reads in the true or false statement, "I am hungry," and we would phrase this as a question as, "Am I hungry?", like that.

Let's do a check here.

A condition is a statement that can be either true or false.

Pause the video to think about your answer.

Welcome back.

A condition is a statement that can be either true or false.

The answer is true.

Well done if you got that right.

Laura says, "Conditions must be phrased as a question with just two options, yes or no." Jacob says, "What about the question, 'What's the weather today?'" Hmm.

Watch the animation.

What's the problem with using this question as a condition? The question that's being used in the animation is, "What's the weather today?" And the robot is showing an error.

Pause the video to have a think about that.

"What's the weather today?", can be answered in many different ways.

"Is it sunny?", and, "Is it raining?", can only be answered with a yes or a no, a true or false.

So they are conditions.

You can see in the animation that the robot is quite happy with those two questions.

Sam says, "I want to write a condition based on the question, 'What shall I do at playtime?'" How could you change this question to be a condition? It will need to be answered with only a yes or a no.

Pause the video to have a think about that.

Here are some possible conditions.

"Shall I read a book?" Or, "Do I want to play a game?" Both of those are conditions.

They can be answered with only a yes or a no.

Let's do a check here.

Which question is not a condition? Is it A, "Are you on your way to school?" B, "Do you eat mushrooms?" Or C, "what date is your birthday?" Pause the video here to have a think about that.

Welcome back.

Which question is not a condition? The answer is C, what date is your birthday? This question cannot be only answered with a yes or a no.

So that makes it not a condition.

Well done if you got that one right.

Okay, it's time to do a task now.

I want you to write your own conditions for these situations.

"What time should I get up in the morning?" "What shall I wear today?" "What shall I have for breakfast?" And, "How will I get home from school?" Remember that they should be questions with only yes or no answers.

It's time to go and work on this task and then you can come back and look at the answers with me.

Welcome back.

You are writing your own conditions for these situations.

The first one reads, "What time should I get up in the morning?" Now with this task, we want to change these questions slightly so that they can be answered with a yes or a no.

So the answer here is, "Shall I get up at 7:00 AM?", because that can be answered with a yes or a no.

The second question reads, the second question reads, "What shall I wear today?" And the answer is, "Do I want to wear jeans today?" Third question reads, "What shall I have for breakfast?" And the answer is, "Should I eat cereal for breakfast?" And the last question reads, "How will I get home from school?" With the answer being, "Will I take the bus home from school?" So your answers might be different from these, and that is okay.

Just make sure that the questions that you're writing can only be answered with a yes or a no.

Well done for all of your hard work in that task.

In the next part of the lesson, you will be designing a conditional loop.

A count-controlled loop uses a number as its condition.

Here is an example of a count-controlled loop.

And number 10 here is the value that you will set how many times the sequence of repeat inside the loop.

In a conditional loop, you can set your own condition.

So you can see in the do until loop that it looks a bit different.

There is the hexagon shape and that is where you will add your own condition to the loop.

True or false? Only one of these loops uses conditions.

So we have got a do 10 times loop and a do until loop here.

Pause the video and think about your answer.

Welcome back.

The question was, only one of these loops uses conditions.

True or false? The answer is false.

Why? Both of these loops use conditions.

One is a count-controlled loop where a number is the condition.

The other is a conditional loop where you set the condition.

Well done if you got that one right.

Read these actions.

"I can act out head, shoulders, knees, and toes until my partner taps their nose." What condition is used? "My partner taps their nose," is the condition here.

What do you do when the condition is false? When the condition is false, you act out heads, shoulders, knees, and toes.

What do you do when the condition is true? When the condition is true, you stop the actions.

This is how conditions work.

This is the same actions written as code.

You can see that we've put the sections of the conditional statement in the coding loop.

We've got do until partner is taps their nose.

Heads, shoulders, knees and toes, actions within the loop.

Izzy says, "What about the statement, 'I am allowed to read until 9:00 PM?'" You can see that we've put this conditional statement in the loop.

We've got do until time is 9:00 PM.

Read my book.

So this means that I will keep reading my book until the time is 9:00 PM.

Let's do a check here.

The statement is, "The light stays green for traffic until someone wants to cross the road." What goes in this empty space? Is it A, road, B, traffic, or C, pressed? Pause the video to think about your answer.

Welcome back.

We are looking at the statement, "The green light stays green for traffic until someone wants to cross the road." What goes in this empty space? The answer is C, pressed.

So we read the code as the green light is on for traffic until the button is pressed.

Well done if you got that one right.

This Crumble programme uses a push button, which is labelled A, being pressed as a condition.

When the button is being pressed, condition is true.

The circuit is described as high, so it's the letters H and I in capital.

When the button is not pressed, the condition is false.

The circuit is described as low and they show this as the capital LO.

The code here reads, "Set the Sparkle to red until the button is pressed.

And then after that, turn the Sparkle off." A push button can be used as an input for a Crumble controller, and so can be used in condition statements.

The push button being pressed is the condition.

This is being shown by the command block A is HI over here.

Use the diagram to connect the button to your Crumble controller.

You should have a battery pack, a Crumble, a Sparkle, and a button.

This algorithm makes a Sparkle flash red and blue until the button is pressed.

Do the following until the button is pressed.

Light the Sparkle red for 0.

1 second.

Light the Sparkle blue for 0.

1 second.

Turn the Sparkle off.

This is the code for the programme.

It will make the Sparkle flash red and blue until the button is pressed.

The first line is the do until conditional loop.

This section will repeat until the condition is met.

The condition is the button pressed.

When the button is pressed, the loop ends.

The Sparkle turns off.

Okay, it's time for you to get ready for your next task.

Write a programme that uses a conditional loop to stop a repeating light pattern.

Your light pattern should use one Sparkle and can have up to five colours.

The condition must be the push button being pressed A is HI.

It is time to go and work on your programme now.

Create a conditional loop to stop a repeating light pattern and when you finish, you can return back to the video.

Welcome back.

Well done for all of your hard work during that task.

Here is an example of a programme that uses a conditional loop to stop a repeating light pattern.

So you can see we've got a do until loop here with the A is HI condition.

That means the button is pressed, so everything inside that loop is going to happen until the button is pressed.

So my Sparkle is going to change colours with some weight in between until the button is pressed and when the button is pressed, it will turn the Sparkle off.

You have worked really hard on your learning today.

Let's go through a summary of controlling with conditions.

A condition is a statement that can be either true or false.

Programmers can use conditions to trigger actions.

When you are writing conditions, they should be questions with only yes or no answers.

In a loop, conditions can be used to set the actions that will be carried out until the condition is met.

A push button can be used to control a Crumble.

A conditional loop is used to stop a repeating light pattern.

Well done for all of your hard work today, and I hope to see you again soon.