Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 116 - 2610_Springdales_C-5
P. 116

    The sprite will ask you to type your favourite fruit. When you press the Enter key, the name of
                  the fruit appears in the speech bubble of the penguin. The name of the fruit then appears in
                  the answer as well as in the variable name on the stage.

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

                      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.

                      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.

                            Premium Edition-V
                    114

| 111 112 113 114 115 116 117 118 119 120 121 |