Page 88 - 2502_Pakistan-kifayat_C-8
P. 88

# Intermediate Level


                               Programming


               Chapter 6




                #Chapter Profile
                    Introduction to Loops                                 Conditions
                    Understanding Functions                               Cloning in Scratch
                    Designing Game






                             Take Off                                                           Century   #Critical Thinking
                                                                                                  21 st
                                                                                                  Skills
                    State whether these statements are true or false.
                    1.  Nesting means putting one thing inside another.
                    2.  Constants can change their values during a program.

                    3.  Variables store values that can change while a program runs.




              In the previous chapter, you learnt about nesting, constants, variables, and loops using pseudocode. You
              also used IF statements and problem-solving techniques. In this chapter, you'll build on that knowledge
              to design and develop more Scratch scripts.

                   INTRODUCTION TO LOOPS


              Sometimes, you need to repeat a task many times, either a set number of times or until something
              happens.  Loops  help  computers do  the  same task again  and  again  without  having  to write the
              instructions over and over. This saves time and makes coding easier.
              For example, if your teacher asks you to clap your hands 10 times, you wouldn’t say “clap” and count
              each clap out loud every time. Instead, you simply keep clapping until you have clapped 10 times.
              So, the action “clap your hands” repeats 10 times — that’s how a loop works! You repeat something a
              certain number of times. A loop in Scratch is a block that repeats an action many times without having
              to write the same instructions again and again. Loops help us save time and make tasks easier by
              avoiding repeated writing of the same instructions.

              Simple Loops

              There are two simple loops in Scratch:

                  repeat block: The repeat loop repeats a set number of times. You decide
                 how many times it repeats. For example, if you use repeat 10, the blocks

                 inside will run 10 times, like moving 10 steps 10 times.
   83   84   85   86   87   88   89   90   91   92   93