Although I have been using conditional blocks in many of my blogs/lessons, I forgot that I have never formally introduced conditional blocks so far:). So let’s cover those today.
The idea of conditional blocks is pretty straight-forward and intuitive. Conditional blocks are the blocks used to make a choice between the execution of two different code chunks.
Here are some of the conditional blocks available in SNAP!:
- block is used to define if a particular code path should be executed or not. The condition to define that decision is entered in the trapezoidal input next to if.
- block is used to choose between 2 different code paths. If the condition input next to if is true, the first code block will be executed, and if it is false, the second one will get executed.
Input blocks to conditional blocks
Now if you are wondering what blocks you should use to define the condition in the trapezoidal input next to if, the answer is simple, any blocks with trapezoidal shape. Some examples of such blocks are:
As you might remember from the blog post a few week ago, these blocks are known as predicate blocks.
I hope you learned something new today. I love to hear from you, so feel free to share your thoughts/feedback in the comments below.