Conditional Statements in scratch

Updated: February 17, 2022
No Credit Card Required
ClaimYour
FreeTrialClass

Transcript

Hey, nice to see you again. Today we're going to learn about CONDITIONAL STATEMENTS.

Last lesson, we covered Boolean Conditions, those are conditions that can be either true or false. Nothing ELSE - just true or false. Today, I want to introduce a second kind of statement, the IF THEN statement. These use Boolean logic, determine IF a statement is true or false and THEN do something like execute a command.

So they are a little bit easier to understand with some examples. Here are some IF THEN statements:

IF it is raining outside, THEN take an umbrella.

IF it is snowing today, THEN school is canceled.

IF you have a temperature, THEN don't come to school.

So the IF part of the statement specifies the condition for you to evaluate.

IF it is raining outside….., is it raining? Yes, the conditions true. Execute the action and take an umbrella.

Here's a simple IF THEN statement using the IF THEN block. What do you think this statement does?.

IF the key space is pressed, THEN move 10 statements.

Code it and see what happens.

When the space key is pressed, the condition is true. So the computer executes the action move 10 steps. Remember to use the Forever Block. The Forever Block is what is known as a LOOP and it instructs the computer to loop back and check the condition over and over again. Otherwise, the computer will execute the code just one time.

Another statement for you. It's called the IF THEN ELSE statement. Here's some IF THEN ELSE statements:

IF it is raining outside, THEN take an umbrella, ELSE wear a hat.

IF it is snowing today, THEN school is canceled, ELSE get on the school bus.

What will happen here? IF the right arrow key is pressed, THEN the condition is true. And the sprite moves 10 steps. IF the condition is false, what happens? That's correct. The sprite moves five steps.

IF THEN ELSE gives us a way to execute an action IF the condition is False.

Now don't worry, if this is a bit new to you. You'll pick it up fast. But that ends today's lesson.

IF you come to the next lesson, THEN I will see you there ELSE, Bye bye

Loading...