Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 89 - 2607_Trackpad_Pro_5.1_flipbook_C1
P. 89

    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.

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

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

                     until the Stop button          is clicked by the user.

                               CREATING A SCRATCH PROJECT

                     As you know, a sprite is controlled by a list of instructions known as code or script.
                     We create scratch programs by putting code blocks together. Let us create some

                     projects in Scratch. Programs are written in Scratch to move sprites in x and y
                     coordinates on the stage area.

                     PROJECT 1: MOVING A SPRITE
                     To move a sprite around the stage, we need to learn how to work with Motion
                     blocks. A sprite can be moved a few steps ahead or turned by different angles. Let

                     us now create a project that instructs a sprite to move.

                     Step  1     From the Events block, drag a          when    clicked   block.

                     Step  2       From the Motion block drag a         move 10  steps    block.

                     Step  3       Click  on the  number 10 and  change it  to           move 50   steps    (The number

                                 determines how far across the screen you want the sprite to move.)

                     Step  4     Drag a    turn    15  degrees    block. The sprite will rotate 15 degrees clockwise.

                                 (To change the angle of turn, change the number of degrees and then
                                 click on the block to make the sprite turn.)

                                                                                     Introduction to Scratch Programming  87

| 84 85 86 87 88 89 90 91 92 93 94 |