Introduction to the IF and IF/ELSE blocks: Programming in Scratch 2.0

COLLEEN LEWIS: We’ll look at a new
block today called an if block. And this is something that’s
in every programming language. It allows us to make decisions
within the program about what we want the program to do. So if I go to the Control
tab, I can see this. If, and then it has a
funny shaped blank, then. To find some of those funny shape
blanks, that I call diamond shape, we can come to the Operators tab. If I drag one of those in, they’ll fit. And it says, if 2 equals 3. And I’ll put something in there. I’ll say play note 60. So if I double click on this, do
you think it will play this note? I don’t think so, because
2 does not equal 3. Let’s try it. Nope. What if I said if 3 equals 3– and
that’s true– then play the note 60? [MUSIC PLAYING] Sounds good. We can do lots more
complicated things here. So we could try a less
than– so 3 is less than 5. Will it play the note? Yeah, it will because that’s true. 3 is less than 5. We have another type of block,
which is an if, then, else. It looks really similar to the first
one, except what I can do is I can say, what happens if this is not true. So if 3 is less than 5,
then I’ll play note 60, and otherwise, or
else, I’ll play a drum. So here, 3 is less than
5, so it’ll play note 60. Let’s listen. [MUSIC PLAYING] If I had something where this wasn’t
true, where 7 is not less than 5, then it won’t play this first note. Instead, it will play this drumbeat. Listen. [MUSIC PLAYING] This green shape is called a predicate. It’s something that
can be true or false. So 7 less than 5? That’s false. That’s not true. And then based upon whether
or not that’s true or not, it’ll either play this
first one or the second one. And this works just
like repeats, where I can have multiple blocks inside of here.

1 Comment

  1. Jack Eatock May 29, 2016 at 1:06 pm

    Thank you so helpful!

Leave a Comment

Your email address will not be published. Required fields are marked *