Predicate Blocks in SNAP!

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:

Operator Palette Predicate Blocks in SNAP!

and in Sensing palette are:

Sensing Palette Predicate Blocks in SNAP!

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.

Predicate Blocks in SNAP! - Predicate Block Result of true or false

Now let’s use this predicate block as an input to the if-else block

Predicate Blocks in SNAP! - Using Predicate Blocks in IF - ElseType the same code in SNAP! and see the results yourself :).

I hope this post helped you understand predicate blocks. Please feel free to leave a comment below if you have any questions/feedback.

Share This:

6 thoughts on “Predicate Blocks in SNAP!

  1. I am extremely impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it is rare to see a nice blog like this one today..

  2. Anytime I research a topic I have no idea what i will discover. I am so very happy to have discovered your complete blogging as it properly covers the questions I have under consideration and also the unmentioned questions which i might have checked for in the future.

  3. Heya i am for the first time here. I came across this board and I to find It truly useful & it helped me out a lot. I’m hoping to provide something again and help others such as you helped me.

Leave a Reply

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