Upper Elementary
Computer Science
Introduction to Conditionals
Objective
Conditional: A command that tells a program how to make a decision if something is true or false
Vocabulary
?
Boolean: A value that can only be true or false
Vocabulary
Review
How do you decide whether to wear a jacket to school?
How do you decide whether to wear a jacket to school?
How do you decide whether to wear a jacket to school?
You make a decision based on if conditions are true. If it’s cold, you wear a jacket. If it’s not, you don’t.
Conditionals in Programming
In programming, we use conditionals to help computers make decisions. A conditional is based on a condition that is either true or false.
Is it cold?
Yes/True
No/False
A value that can only be true or false is called a boolean.
wear jacket
don’t wear jacket
Here’s an activity to practice conditionals in everyday life.
We use conditionals to make decisions all the time.
Let’s make some decisions with conditionals!
Complete the sentence:
If it’s raining, __________.
Complete the sentence:
If it’s hot outside, __________.
Complete the sentence:
If my room is messy,
__________.
Using conditionals in Scratch.
Find the "if/then" block in the Control section.
Using conditionals in Scratch.
The condition goes in the diamond space.
Use the blue Sensing blocks to check the condition.
Using conditionals in Scratch.
If the condition is true, the blocks inside the "if/then" block will run.
Is the sprite touching this specific color?
Yes/True: Say “I like purple.”
No/False: Do nothing.
Using conditionals in Scratch.
Important note: the computer only checks the condition once.
What do we use if we want to repeat a command multiple times?
Using conditionals in Scratch.
Adding a “forever” loop around the conditional will keep the code running inside of it until the program stops.
We will make a beach scene program with conditionals!
Guided Practice
Program the cat sprite to move.
Add an “if/then” conditional.
Add a “touching color” block.
Add a “say” block to show when the condition is true.
Test your program.
Add a “forever” loop.
Program the cat to say “Let’s Play” if touching the Karel sprite.
Independent Practice
Add more to the beach scene.
Extensions
If you have more time…
Showcase!
Reflection
Can you give an example of a conditional from our lesson?
Can you think of other situations in your daily life where you use if/then logic?