Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 80 - 2616_V iCode_C-5
P. 80

    We can also write this in two ways:

                        1.  if                                                2.  if
                                 mango is available                                     mango is available
                            then                                                  then
                                 make the mango shake                                   make the mango shake
                                                                                  else
                                                                                        make cold coffee

                        In such situations, we use conditional blocks. Scratch has two conditional blocks.

                      They are:
                      1.   If,then block: In this block if the condition is true, the blocks inside conditional

                         block will run. If the condition is false, the blocks inside 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 fish and change the backdrop to Underwater 2.

                      Drag the Events 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.

                           78    Premium Edition-V

| 75 76 77 78 79 80 81 82 83 84 85 |