Introducing Conditional Blocks

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!:

  1. If Block 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. 
  2. If else Block in SNAP! 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:

Input blocks to conditional blocks - Predicate BlocksAs 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.

Share This:

A geek, a techie, a daughter, a sister and a wife. Worked at Microsoft for 8 years and currently working at Amazon Web Services (AWS). All opinions expressed here are my own and has no correlation to my employer or ex-employers!

Leave a Reply

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