Page 77 - TP_iPlus_V2.1_Class6
P. 77

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. Then 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.

                 For example, if the number you entered is less than 50, the sprite will turn 15 degrees to the right
                 otherwise, the sprite will move 20 steps backward.

























                  i +  USE OF LOOPING CONTROL BLOCKS

                 All the programs or projects you have developed till now run 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 or
                 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 times.


                                    The Repeat Until block is used to run a set of instructions until a condition
                                    is satisfied.


                 The  Forever block is  used to run a set of instructions continuously until
                 stopped. The instructions inside this block will be executed in a loop until the

                 Stop button       is clicked by the user.

                 The Repeat and Repeat Until blocks can be used to display the multiplication table of a number
                 input by the user. The script for the sprite can be like this (using Repeat Until block).






                                                                                                                  75
                                                                           Scratch Programming—Game Creation
   72   73   74   75   76   77   78   79   80   81   82