Page 88 - TP_Prime_v2.2_Class_5
P. 88

Conditional Blocks

                  Many times, you have to do a task which is dependent on some conditions. For example,

                  you have to make mango shake. There are two conditions:
                  a)   Go to the refrigerator and check if there are mangoes. If mangoes are there, then

                      you will make mango shake.
           Prime (Ver. 2.2)-V       Here the condition is the availability of mango.
                  b)   If the mangoes are not there, you will make cold coffee.



                      We can also write this in two ways:
                      1.  if
                                                                            2. if


                            mango is available
                                                                              then
                          then                                                        mango is available
                            make the mango shake                                      make the mango shake
          86
                                                                              else
                                                                                      make cold coffee
                  In such situations, we use the conditional blocks. Scratch has two conditional blocks:

                  1.  If…then block: In this block if the condition is true, the blocks inside the conditional
                      block will run. If the condition is false, the blocks inside the conditional block will

                      not run. Only the blocks outside the conditional block will run.

                  2.  If…then…..else block: In this block if the condition is true, the blocks inside then
                      condition will run. If the condition is false, the blocks inside else condition will run.

                      You can also use the forever and repeat blocks with these blocks.
                  Let us make a small script.

                  Change the sprite to butterfly and change
                  the backdrop to flowers.

                  Drag the  Event block,  when  green  flag

                  clicked to the script area. Drag the control
                  block, forever to the script area and put
                  it to the green flag block. Drag the move

                  block and put it inside the forever block.
                  Now, drag the if on edge, bounce block
                  and put it inside the forever block.

                  Now, put the control block if…then inside
                  the forever block and snap the sensing block, touching color...? in the hexagon of

                  the if loop.
   83   84   85   86   87   88   89   90   91   92   93