Page 67 - 2619_PlusGPT V2.1_C-6
P. 67

This variable 'Fruit' is a string variable as we are saving names in the variable. If you save numbers in

                 a variable, say, 'Mobile', it will be a numeric variable.


                        CONDITIONAL BLOCKS


                 Many times, you have to do a task which is dependent on some condition. 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.
                 b.   If the mangoes are not there, you will make cold coffee.

                    Here the condition is the availability of mango.

                    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.



                                                                                              Scratch Programming  65
   62   63   64   65   66   67   68   69   70   71   72