Relational operators are greater than, less than, and equal. In Scratch, they look like ones on the left side below (green blocks).
Notice that inside each block are two ovals capable of handling or accepting values. So any oval blocks in Scratch, like those on the right side above, can be put inside each of those ovals.
Relational operators are used for checking relationships between two values, hence, two ovals. Between the two ovals is the relational operator.
Each time we evaluate two values with the relational operator, it should always give us a True or False result. Let’s look at the examples below:
- 10 > 6 should result to True.
- 4 = 4 should give a True answer
- 6 < 3 should give a False answer
We use these relational operator inside an If-Condition statement. Here’s how an If-Condition and If-Condition-Else blocks look like in Scratch.
Notice that the shape between the words “If” and “then” is a hexagon. This means that any hexagon block in Scratch can be put inside there. The relational operator blocks are with hexagonal shape.
What do you think will be the result for each of the If-Condition statement below?
Since 3 is not greater than 50, then the first If-Condition statement above should be false.
Since 11 is a lower number than 21, then the second If-Condition statement above should be true.
Since 5 is equal to 5, then the third If-Condition statement is true.
The blocks inside the If-Condition
With If-Condition statement, once the condition evaluates to true, then the block(s) inside it will be executed. If the condition leads to false, then the block(s) inside it will be ignored.
Let’s look again at the examples above:
- Do you think the words “Hello there!” will be displayed? The answer is no since the condition evaluates to false.
- Do yo think the words “Eleven here!” will be displayed? The answer is yes since the condition leads to true.
- Do you think the words “The same!” will be displayed? Yes, because the condition is true.
This is how the If-Condition statement works: whenever the condition evaluates to true then the blocks inside it will be executed, otherwise, the computer will simply ignore and proceed to the blocks outside the If-Condition block.
Here’s a project that you can make in Scratch using the relational operators and the If-Condition statement.