Page 136 - ScienceStd4
P. 136

Program control structures

              Program control structures refer to how the flow of computer
              instructions is  managed.  There are three types  of  program
              control structures namely sequence, repetition and selection.
          FOR ONLINE READING ONLY

              Sequence structure in programming

              In programming, a sequence structure follows the order of flow
              of instructions or blocks from top to bottom. The first block is
              executed before the next block. For  example, in Figure 32,
              blocks will be executed as follows.


              1.  The ‘when clicked’ block is executed first.


              2.  The ‘go to (random position)’ block is executed next.


              3.  The ‘turn (Q) 15 degrees’ block  is then executed

              4.  Lastly, the ‘if on edge, bounce’ block is executed.





















                               Figure 32: Sequence structure in programming

              Thus,  the  flow  becomes  as  follows:  ‘When clicked  →  go to
              (random position) → turn (15) degrees → if on edge, bounce’.


              Repetition structure in programming

              In computer programming, you might need some action to
              repeat several times. For example, you might need movement



                                                   129




                                                                                            14/01/2025   18:38
     SCIENCE AND TECHNOLOGY STD 4.indd   129                                                14/01/2025   18:38
     SCIENCE AND TECHNOLOGY STD 4.indd   129
   131   132   133   134   135   136   137   138   139   140   141