In the beginning of the year, we discussed Reporter Blocks and their use cases. Today lets’s talk about a special type of Reporter Blocks, known as Predicate blocks. Predicate blocks are of trapezoidal shape and must return true or false. Some of the examples of predicate blocks in Operators palette are:
and in Sensing palette are:
Why are predicate blocks special?
Predicate blocks are considered special cases of reporter blocks, since they can be used in conditional statements and eventually defining the flow of the code.
Playing with Predicate Blocks
Now let’s test some simple predicate blocks.
Drag less than (<) predicate block to the scripting area, and type in 2 random numbers. For this example, I typed in 2 and 5 as an input. Now, click on it and you will see the result of the equation. Since I typed in 2<5 for this example, it shows the result as true.
Now let’s use this predicate block as an input to the if-else block
I hope this post helped you understand predicate blocks. Please feel free to leave a comment below if you have any questions/feedback.