Lesson video

In progress...

Loading...

Hello, my name is Miss Powell and welcome to Computing.

I'm so pleased that you decided to join me here today.

In today's lesson, we're going to be learning how to use conditional statements with two outcomes.

Let's get started.

Welcome to today's lesson from the unit, "Using selection in programming to develop a quiz." This lesson is called "Outcomes from selection statements" and by the end of today's lesson, you'll be able to explain that a conditional statement can connect a condition to an outcome.

We'll be using these keywords throughout today's lesson.

Let's take a look at them.

The first word is repetition.

Repetition.

This means part of a programme where one or more commands are run multiple times in the loop.

The next one is infinite loop.

Infinite loop.

This is a chunk of code that runs a section of the programme continuously.

The third word is outcome.

Outcome.

These are the actions that come from a condition being True or False.

Lesson outline, "Outcomes from selection statements." This lesson is split into two sections.

In the first section, we'll determine programme outcomes.

In the second section, we'll build conditional statements with two outcomes.

Let's get started with the first section.

Determine programme outcomes.

Look at these algorithms. Which dance will finish first? We've got here on the left, Dance 1, repeat 2 times, step forward, spin around, touch the ground.

We have Dance 2, forever, clap, touch the floor.

Pause the video and have a quick think.

Which will finish first? Well done for having a go.

Aisha says, "Dance 2 has fewer instructions, so it will be finished before Dance 1." Do you think Aisha is correct? Dance 2 does have fewer instructions but it uses forever as its form of repetition.

The instructions will be repeated endlessly.

Dance 2 will go on forever.

In the first algorithm, the sequence will only be repeated twice.

Repeat 2 times.

Dance 1 will finish First.

Look at this code.

Let's have a look at it here in Scratch.

When green flag clicked, if key a is pressed, then turn clockwise 15 degrees.

Sam says, "When the a key is pressed, the sprite will turn 15 degrees." What is the code missing? Sam says, "My programme isn't working! Nothing happens when I press the a key." Pause the video and have a quick think.

What's missing in this code? This code will only check the condition once.

At the start of the programme when a green flag is clicked, it will check the condition once and very quickly.

It is missing an infinite forever loop.

For the programme to work, the condition needs to be checked continually.

So, our condition, is a key pressed? Yes or no? Needs to be checked continuously.

For a player to press that key, that gives them time to press it.

By adding a forever loop, the code will work.

"It's working now! The infinite loop means the condition is checked continually." Here is the infinite loop.

What is needed for a condition to be checked continually? Is it a, forever, b, repeat, or c, if and then? Which block do you think would be needed? Pause the video and have a think.

Well done, it's a.

Repetition is part of a programme where one or more commands are run multiple times in a loop.

Here is an example of repetition.

You've got our forever block.

If key a is pressed, then turn clockwise 15 degrees.

Those commands are running continuously inside the forever block.

Selection is part of a programme where if a condition is met, then a set of commands is run.

Here's our selection.

If key a is pressed, then turn clockwise 15 degrees.

Our Sprite will turn 15 degrees clockwise only and when a key is pressed.

The programme only performs actions when it checks the condition.

By using an infinite loop, the action is carried out every time the condition is met.

Without using an infinite loop, the condition is only checked once.

In this example, if we were running this code, every time I press the a key, my sprite will turn 15 degrees.

I can press my a key as many times as I'd like and I can get my sprite to turn as many times as I like.

Well done for having a go.

I'd like you to match the word or phrase to the definition.

The words that we have here on the left are repetition, condition, and selection, and the phrases and definitions are a statement that can be either True or False, part of a programme where if a condition is met, then a set of commands is run, and part of a programme where one or more commands are run multiple times in the loop.

Pause the video and see if you can match the word or phrase to the definition.

Repetition.

This is part of a programme where one or more commands are run multiple times in a loop.

Condition is a statement that can be either True or False.

Selection is part of a programme where if a condition is met, then a set of commands is run.

Fantastic.

Well done for having a go.

In coding, we call the actions that happen because of selection outcomes.

Jacob says, "The outcome of pressing the a key is that the sprite turns 15 degrees clockwise." An outcome is the action that is carried out when a condition is True.

Let's take a little look here at the coded scratch.

When green flag clicked, forever loop, if touching mouse-pointer, then play sound Meow until done.

Andeep says, "When the sprite touches the mouse pointer, the outcome is that it plays the meow sound." This is the action that happens when the condition is True.

So the condition is, yes or no, is the sprite touching the mouse pointer? The outcome is if True, play the meow sound.

I have a task here for you.

I'd like you to open a Chicken Condition project on oak.

link/chicken-condition.

Use Sprite 1 one for this task.

Predict the outcome of the code sequences shown on the next slides, then build and test them to see if you're correct.

Pause the video to finish the task.

Number one, predict the outcome of the code sequence, then build and test it.

Let's take a look at it.

When green flag clicked, here's our event bot.

We have a loop, the forever loop.

Within that loop, it says, if down key arrow is pressed, then change size by -15.

What do you think will happen in this code sequence? What do you think the outcome will be? Pause the video and have a think.

Super thinking.

When I press the down arrow key, the sprite will get smaller by 15.

That's the outcome.

Number two, predict the outcome of the code sequence, then build and test it.

Let's take a look at it together.

When green flag clicked, forever loop, if d key pressed, then change colour effect by 25, say, "D is for disco!" for 0.

5 seconds, play sound Dance Funky until done.

What do you think the outcome will be if the condition is True? The outcome is when I press D key, the sprite will change colour, say "D is for Disco!" for half a second and then play the Dance Funky sound.

Let's take a look at this one.

Predict the outcome of the code sequence, then build and test it.

When green flag click, forever loop.

If up key arrow is pressed, then say, "It's jumping time!" for 2 seconds, change y by 50.

What do you think the outcome will be if the condition is True? Pause the video to finish the task.

When I press the up arrow, the sprite will say "It's jumping time!" for 2 seconds, then it will jump up 50.

I have another task here for you.

You're doing so well.

I'd like you to predict the outcome of the code sequence, then build and test it.

When green flag clicked, forever loop, if the r key pressed, then set size to 100%, set colour effect to 0.

Pause the video to have a look at the code sequence, then build and test it.

The answer is this is a reset sequence.

When I press the r key, the sprite will go back to its normal size and colour.

Well done, you've done so well looking at those code sequences.

Number five, create your own code sequence for Sprite 1.

Your code must include repetition, an if-then block with a condition, at least one action inside the if-then block.

What would happen if you did not use repetition in your programme? Pause the video to finish the task.

I'd like to give you some feedback, "Determine programme outcomes." Create your own code sequence.

What would happen if you did not use repetition? The code would check the condition only once when the green flag is clicked.

If I wasn't pressing the left arrow at that exact moment, nothing would happen.

Fantastic.

You've done so well in the first section, "Determine programme outcomes." Let's move on to the second section, "Build conditional statements for two outcomes." This is called a conditional statement.

It is used to describe how a condition is connected to outcomes.

If it is after 7 o'clock, then get out of bed and get ready for school.

The condition is it's after 7 o'clock, yes or no.

The outcome is then get out bed and get ready for school.

What happens if the condition is True? If it's True, the outcome will happen.

What happens if the condition is False? If it's False, nothing happens.

Jacob sometimes goes in the car to school.

He sometimes takes the bus to school.

Jacob says, "On Tuesdays and Thursdays, I go to my granddad's house after school.

I take the bus on those days." You can use another structure for selection.

This is the if-then-else structure.

If the day starts with the letter T, then take the bus to school, else walk to school.

This allows another outcome to happen.

We have an outcome here.

Take the bus to school.

This happens if the condition is True, so Jacob will take the bus to school if the day starts with the letter T, so on Tuesday, on Thursday.

We have another outcome here which is walk to school.

This will happen if the condition is False.

So on the other days, Monday, Wednesday, and Friday, Jacob will walk.

If it's used to give the condition which is the day starts with the letter T.

Then, it's used to give the actions to carry out when the condition is True.

Else is used to give the actions to carry out when the condition is False.

This has been written of indentation to make it clear that the commands are linked.

True or false? In a conditional statement, the if-then-else structure lets you set three different outcomes.

Is that true or false? The answer's false.

Why is that? A conditional statement has only two outcomes, True or False.

Well done.

There are two condition blocks in Scratch.

They're both used to check whether a condition is True.

Here on the left we have if and then, and on the right we have if-then-else.

The if-then-else block is used to check whether a condition is True or False.

If-then-else.

The condition goes in this hexagonal shape.

If the condition is True, the outcome goes in this space.

If the condition is False, the outcome goes in this space.

Aisha is looking at her school timetable.

If she has music on that day, then she has to bring her sheet music.

If she does not have music, she should bring her reading book.

How would this be structured using if-then-else? Pause the video and have a quick think.

If you have music, then bring your sheet music, else bring your reading book.

Look at Sam's code.

If space key is pressed, then move 10 steps, else turn 15 degrees clockwise.

Why would this code not work? Pause the video and have a quick think.

Sam says, "It needs an infinite loop to check the condition continually." Forever, if space key is pressed, then move 10 steps, else turn 15 degrees clockwise.

The sprite will forever turn 15 degrees clockwise.

When you press the space bar, the sprite will move 10 steps.

By including the infinite loop, it gives the player time to press the space key.

Task B, "Build conditional statements with two outcomes." Open the Chicken Condition project on oak.

link/chicken-condition.

Number one, use the Programming two outcomes sheet.

Choose a condition, a True outcome, and a False outcome.

On Sprite 2, construct a programme using your choices.

Number two, write a conditional statement of your programme using if-then-else.

Pause the video to finish the task.

That is super.

I'd like you to try another task, Programming two outcomes.

Choose a condition, a True outcome, and a False outcome.

Let's look at the table.

We have conditions here in the left-hand column.

When space key pressed, when q key pressed, when h key pressed, when left arrow key pressed, when number 2 pressed.

Outcome if True, say, "Hello!" for two seconds, change size by 10, next costume, play sound Meow until done.

Outcome if False, turn clockwise 15 degrees, turn anti-clockwise 15 degrees, change colour effect by 10, move 10 steps, if on edge, bounce.

Pause the video to choose a condition, a True outcome, and a False outcome.

Number one, open Chicken Condition Example on oak.

link/chicken-example.

You may have chosen Sprite 2.

Here's an example.

When green flag clicked, forever, if left arrow key press, then next costume, else move 10 steps, if on edge, bounce.

Write a conditional statement of your programme using if-then-else.

Forever, if the left arrow key is pressed, then change to the next costume, else move 10 steps, if on edge, bounce.

Fantastic.

You've done so well in today's lesson.

Let's summarise, "Outcomes from selection statements." Selection is part of a programme where if a condition is met, then a set of commands is run.

Conditional statements use True or False conditions to determine which outcome will happen.

The structure if-then-else allows a True and False outcome.

If-then-else blocks use repetition.

They need to operate inside an infinite loop in order to check the condition continuously.