Page 135 - TGPT_V5.0_C5_Flipbook
P. 135

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, as they are loop blocks.


                      LOOPS

                 All the programs or projects developed till now ran only once. If you want to run a set of

                 statements more than once, you will either run the code again or write the script again. In
                 Scratch, we can save our time and effort by repeating the code without writing the program
                 again or writing the script again. The automatic running of a set of instructions more than once
                 is called looping. The blocks for looping are given in Control category.

                 The Repeat() block is used to run a set of instructions for a specified number of           repeat  10

                 times.


                 The Forever block is used to run a set of instructions continuously until stopped.          forever
                 The instructions inside this block will be executed in a loop until the Stop button
                      is clicked by the user.






                                                                                         Conditional Blocks in Scratch 133
   130   131   132   133   134   135   136   137   138   139   140