Page 85 - iPro_trackGPT_V5_Class6
P. 85

If         <strawberries                are    If <strawberries are available> then
                  available> then                                        Make the strawberry smoothie

                          Make the strawberry Else
                  smoothie                                               Make hot chocolate

                 This approach allows you to define actions based on the outcome of a condition.

                     if...then: This block executes the commands inside it only if the
                    specified condition is true. If the condition is false, the commands
                    within the block are not executed, and only the commands

                    outside the block will run.
                     if...then...else: This block runs the commands inside the “Then”

                    section if the condition is true. If the condition is false, it executes
                    the commands in the “Else” section instead.
                 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
                                                                                           Example of a conditional script
                 steps backward.
                 The output of the program will be similar to this.























                    USE OF LOOPS BLOCKS

                 So far, all the programs or projects you’ve created run only once. If you want to repeat a set of
                 actions more than once, you would either have to run the code again or write the script again.
                 But in Scratch, you can save time and effort by repeating the code without needing to rewrite or
                 rerun the program. This automatic repetition of instructions is known as looping. You can find

                 blocks for looping in the Control category in Scratch.
                 The Repeat block allows you run a set of instructions a specific number of
                 times.








                                                                          Scratch Programming— Game Creation     83
   80   81   82   83   84   85   86   87   88   89   90